|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use POData\UriProcessor\ResourcePathProcessor\SegmentParser\KeyDescriptor; |
|
4
|
|
|
use POData\Providers\Metadata\ResourceSet; |
|
5
|
|
|
use POData\Providers\Metadata\ResourceProperty; |
|
6
|
|
|
use POData\Providers\Query\IQueryProvider; |
|
7
|
|
|
require_once "WordPressMetadata.php"; |
|
8
|
|
|
require_once "POData\Providers\Query\IDataServiceQueryProvider2.php"; |
|
9
|
|
|
|
|
10
|
|
|
/** The name of the database for WordPress */ |
|
11
|
|
|
define('DB_NAME', 'wordpress'); |
|
12
|
|
|
|
|
13
|
|
|
/** MySQL database username */ |
|
14
|
|
|
define('DB_USER', 'root'); |
|
15
|
|
|
|
|
16
|
|
|
/** MySQL database password */ |
|
17
|
|
|
define('DB_PASSWORD', 'root'); |
|
18
|
|
|
|
|
19
|
|
|
/** MySQL hostname */ |
|
20
|
|
|
define('DB_HOST', 'localhost'); |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
class WordPressQueryProvider implements IQueryProvider |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Handle to connection to Database |
|
27
|
|
|
*/ |
|
28
|
|
|
private $_connectionHandle = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Reference to the custom expression provider |
|
32
|
|
|
* |
|
33
|
|
|
* @var NorthWindDSExpressionProvider |
|
34
|
|
|
*/ |
|
35
|
|
|
private $_wordPressMySQLExpressionProvider; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Constructs a new instance of WordPressQueryProvider |
|
39
|
|
|
* |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->_connectionHandle = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true); |
|
|
|
|
|
|
44
|
|
|
if ($this->_connectionHandle) { |
|
45
|
|
|
} else { |
|
46
|
|
|
die(print_r(mysql_error(), true)); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
mysql_select_db(DB_NAME, $this->_connectionHandle); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* (non-PHPdoc) |
|
54
|
|
|
* @see POData\Providers\Query.IQueryProvider::canApplyQueryOptions() |
|
55
|
|
|
*/ |
|
56
|
|
|
public function handlesOrderedPaging() |
|
57
|
|
|
{ |
|
58
|
|
|
return true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* (non-PHPdoc) |
|
63
|
|
|
* @see POData\Providers\Query.IQueryProvider::getExpressionProvider() |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getExpressionProvider() |
|
66
|
|
|
{ |
|
67
|
|
|
if (is_null($this->_wordPressMySQLExpressionProvider)) { |
|
68
|
|
|
$this->_wordPressMySQLExpressionProvider = new WordPressDSExpressionProvider(); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $this->_wordPressMySQLExpressionProvider; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Gets collection of entities belongs to an entity set |
|
76
|
|
|
* |
|
77
|
|
|
* @param ResourceSet $resourceSet The entity set whose |
|
78
|
|
|
* entities needs to be fetched |
|
79
|
|
|
* @param string $select For future purpose,no need to pass it |
|
80
|
|
|
* @param string $orderby For future purpose,no need to pass it |
|
81
|
|
|
* @param string $top For future purpose,no need to pass it |
|
82
|
|
|
* @param string $skip For future purpose,no need to pass it |
|
83
|
|
|
* |
|
84
|
|
|
* @return array(Object) |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getResourceSet(ResourceSet $resourceSet, $filter = null, $select = null, $orderby = null, $top = null, $skip = null) |
|
87
|
|
|
{ |
|
88
|
|
|
$resourceSetName = $resourceSet->getName(); |
|
89
|
|
|
if ($resourceSetName !== 'Posts' |
|
90
|
|
|
&& $resourceSetName !== 'Tags' |
|
91
|
|
|
&& $resourceSetName !== 'Categories' |
|
92
|
|
|
&& $resourceSetName !== 'Comments' |
|
93
|
|
|
&& $resourceSetName !== 'Users' |
|
94
|
|
|
) { |
|
95
|
|
|
die('(WordPressQueryProvider) Unknown resource set ' . $resourceSetName); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$returnResult = array(); |
|
100
|
|
|
switch ($resourceSetName) { |
|
101
|
|
|
case 'Posts': |
|
102
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
|
103
|
|
|
." wp_posts.post_type = 'post'" |
|
104
|
|
|
." AND wp_posts.post_status = 'publish'"; |
|
105
|
|
|
if ($filter !== null) { |
|
106
|
|
|
$query .= " AND $filter"; |
|
107
|
|
|
} |
|
108
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
109
|
|
|
$returnResult = $this->_serializePosts($stmt); |
|
110
|
|
|
break; |
|
111
|
|
|
case 'Tags': |
|
112
|
|
|
$query = "SELECT t.*, tt.description" |
|
113
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
|
114
|
|
|
." ON tt.term_id = t.term_id" |
|
115
|
|
|
." WHERE tt.taxonomy = 'post_tag'"; |
|
116
|
|
|
if ($filter !== null) { |
|
117
|
|
|
$query .= " AND $filter"; |
|
118
|
|
|
} |
|
119
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
120
|
|
|
$returnResult = $this->_serializeTags($stmt); |
|
121
|
|
|
break; |
|
122
|
|
|
case 'Categories': |
|
123
|
|
|
$query = "SELECT t.*, tt.description" |
|
124
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
|
125
|
|
|
." ON tt.term_id = t.term_id" |
|
126
|
|
|
." WHERE tt.taxonomy = 'category'"; |
|
127
|
|
|
if ($filter !== null) { |
|
128
|
|
|
$query .= " AND $filter"; |
|
129
|
|
|
} |
|
130
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
131
|
|
|
$returnResult = $this->_serializeCategories($stmt); |
|
132
|
|
|
break; |
|
133
|
|
|
case 'Comments': |
|
134
|
|
|
$query = "SELECT * FROM `wp_comments` WHERE" |
|
135
|
|
|
." wp_comments.comment_approved = 1"; |
|
136
|
|
|
if ($filter !== null) { |
|
137
|
|
|
$query .= " AND $filter"; |
|
138
|
|
|
} |
|
139
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
140
|
|
|
$returnResult = $this->_serializeComments($stmt); |
|
141
|
|
|
break; |
|
142
|
|
|
case 'Users': |
|
143
|
|
|
$query = "SELECT * FROM `wp_users`"; |
|
144
|
|
|
//print "<br>Filter:".$filter; |
|
145
|
|
|
if ($filter !== null) { |
|
146
|
|
|
$query .= " AND $filter"; |
|
147
|
|
|
} |
|
148
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
149
|
|
|
//$data = mysql_fetch_assoc($stmt); |
|
150
|
|
|
$returnResult = $this->_serializeUsers($stmt); |
|
151
|
|
|
break; |
|
152
|
|
|
} |
|
153
|
|
|
mysql_free_result($stmt); |
|
|
|
|
|
|
154
|
|
|
return $returnResult; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Gets an entity instance from an entity set identifed by a key |
|
159
|
|
|
* |
|
160
|
|
|
* @param ResourceSet $resourceSet The entity set from which an entity |
|
161
|
|
|
* needs to be fetched |
|
162
|
|
|
* @param KeyDescriptor $keyDescriptor The key to identify the entity |
|
163
|
|
|
* to be fetched |
|
164
|
|
|
* |
|
165
|
|
|
* @return object|null Returns entity instance if found else null |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getResourceFromResourceSet(ResourceSet $resourceSet, KeyDescriptor $keyDescriptor) |
|
168
|
|
|
{ |
|
169
|
|
|
$resourceSetName = $resourceSet->getName(); |
|
170
|
|
|
if ($resourceSetName !== 'Posts' |
|
171
|
|
|
&& $resourceSetName !== 'Tags' |
|
172
|
|
|
&& $resourceSetName !== 'Categories' |
|
173
|
|
|
&& $resourceSetName !== 'Comments' |
|
174
|
|
|
&& $resourceSetName !== 'Users' |
|
175
|
|
|
) { |
|
176
|
|
|
die('(WordPressQueryProvider) Unknown resource set ' . $resourceSetName); |
|
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
$namedKeyValues = $keyDescriptor->getValidatedNamedValues(); |
|
180
|
|
|
$keys = array(); |
|
181
|
|
|
foreach ($namedKeyValues as $key => $value) { |
|
182
|
|
|
$keys[] = "$key = '$value[0]' "; |
|
183
|
|
|
} |
|
184
|
|
|
$conditionStr = implode(' AND ', $keys); |
|
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
switch ($resourceSetName) { |
|
187
|
|
|
case 'Posts': |
|
188
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
|
189
|
|
|
." wp_posts.post_type = 'post'" |
|
190
|
|
|
." AND wp_posts.post_status = 'publish'" |
|
191
|
|
|
." AND wp_posts.ID = " . $namedKeyValues['PostID'][0]; |
|
192
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
//If resource not found return null to the library |
|
195
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
196
|
|
|
return null; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
200
|
|
|
$result = $this->_serializePost($data); |
|
201
|
|
|
break; |
|
202
|
|
|
case 'Tags': |
|
203
|
|
|
$query = "SELECT t.*, tt.description" |
|
204
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
|
205
|
|
|
." ON tt.term_id = t.term_id" |
|
206
|
|
|
." WHERE tt.taxonomy = 'post_tag'" |
|
207
|
|
|
." AND t.term_id = " . $namedKeyValues['TagID'][0]; |
|
208
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
//If resource not found return null to the library |
|
211
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
212
|
|
|
return null; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
216
|
|
|
$result = $this->_serializeTag($data); |
|
217
|
|
|
break; |
|
218
|
|
|
case 'Categories': |
|
219
|
|
|
$query = "SELECT t.*, tt.description" |
|
220
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
|
221
|
|
|
." ON tt.term_id = t.term_id" |
|
222
|
|
|
." WHERE tt.taxonomy = 'category'" |
|
223
|
|
|
." AND t.term_id = " . $namedKeyValues['CategoryID'][0]; |
|
224
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
225
|
|
|
|
|
226
|
|
|
//If resource not found return null to the library |
|
227
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
228
|
|
|
return null; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
232
|
|
|
$result = $this->_serializeCategory($data); |
|
233
|
|
|
break; |
|
234
|
|
|
case 'Comments': |
|
235
|
|
|
$query = "SELECT * FROM `wp_comments`" |
|
236
|
|
|
." WHERE comment_approved = 1" |
|
237
|
|
|
." AND comment_ID = " . $namedKeyValues['CommentID'][0]; |
|
238
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
//If resource not found return null to the library |
|
241
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
242
|
|
|
return null; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
246
|
|
|
$result = $this->_serializeComment($data); |
|
247
|
|
|
break; |
|
248
|
|
|
case 'Users': |
|
249
|
|
|
$query = "SELECT * FROM `wp_users` WHERE ID = " . $namedKeyValues['UserID'][0]; |
|
250
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
//If resource not found return null to the library |
|
253
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
254
|
|
|
return null; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
258
|
|
|
$result = $this->_serializeUser($data); |
|
259
|
|
|
break; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
mysql_free_result($stmt); |
|
|
|
|
|
|
263
|
|
|
return $result; |
|
|
|
|
|
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Get related resource set for a resource |
|
268
|
|
|
* |
|
269
|
|
|
* @param ResourceSet $sourceResourceSet The source resource set |
|
270
|
|
|
* @param mixed $sourceEntityInstance The resource |
|
271
|
|
|
* @param ResourceSet $targetResourceSet The resource set of |
|
272
|
|
|
* the navigation property |
|
273
|
|
|
* @param ResourceProperty $targetProperty The navigation property to be |
|
274
|
|
|
* retrieved |
|
275
|
|
|
* @param string $select For future purpose,no need to pass it |
|
276
|
|
|
* @param string $orderby For future purpose,no need to pass it |
|
277
|
|
|
* @param string $top For future purpose,no need to pass it |
|
278
|
|
|
* @param string $skip For future purpose,no need to pass it |
|
279
|
|
|
* |
|
280
|
|
|
* @return object[] Array of related resource if exists, if no |
|
281
|
|
|
* related resources found returns empty array |
|
282
|
|
|
*/ |
|
283
|
|
|
public function getRelatedResourceSet(ResourceSet $sourceResourceSet, |
|
284
|
|
|
$sourceEntityInstance, |
|
285
|
|
|
ResourceSet $targetResourceSet, |
|
286
|
|
|
ResourceProperty $targetProperty, |
|
287
|
|
|
$filter = null, $select = null, $orderby = null, $top = null, $skip = null |
|
288
|
|
|
) { |
|
289
|
|
|
$result = array(); |
|
290
|
|
|
$srcClass = get_class($sourceEntityInstance); |
|
291
|
|
|
$navigationPropName = $targetProperty->getName(); |
|
292
|
|
|
|
|
293
|
|
|
switch (true) { |
|
294
|
|
|
case ($srcClass == 'Post'): |
|
295
|
|
|
if ($navigationPropName == 'Tags') { |
|
296
|
|
|
$query = "SELECT t.*, tt.description" |
|
297
|
|
|
." FROM wp_terms AS t" |
|
298
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
299
|
|
|
." ON tt.term_id = t.term_id" |
|
300
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
301
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
302
|
|
|
." WHERE tt.taxonomy IN ('post_tag')" |
|
303
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)"; |
|
304
|
|
|
if ($filter !== null) { |
|
305
|
|
|
$query .= " AND $filter"; |
|
306
|
|
|
} |
|
307
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
308
|
|
|
if ($stmt === false) { |
|
309
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
$result = $this->_serializeTags($stmt); |
|
313
|
|
|
} elseif ($navigationPropName == 'Categories') { |
|
314
|
|
|
$query = "SELECT t.*, tt.description" |
|
315
|
|
|
." FROM wp_terms AS t" |
|
316
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
317
|
|
|
." ON tt.term_id = t.term_id" |
|
318
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
319
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
320
|
|
|
." WHERE tt.taxonomy IN ('category')" |
|
321
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)"; |
|
322
|
|
|
if ($filter !== null) { |
|
323
|
|
|
$query .= " AND $filter"; |
|
324
|
|
|
} |
|
325
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
326
|
|
|
if ($stmt === false) { |
|
327
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
$result = $this->_serializeCategories($stmt); |
|
331
|
|
|
} else if ($navigationPropName == 'Comments') { |
|
332
|
|
|
$query = "SELECT * FROM `wp_comments`" |
|
333
|
|
|
." WHERE comment_approved = 1" |
|
334
|
|
|
." AND comment_post_ID = $sourceEntityInstance->PostID"; |
|
335
|
|
|
if ($filter !== null) { |
|
336
|
|
|
$query .= " AND $filter"; |
|
337
|
|
|
} |
|
338
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
339
|
|
|
if ($stmt === false) { |
|
340
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
$result = $this->_serializeComments($stmt); |
|
344
|
|
|
} else { |
|
345
|
|
|
die('Post does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
346
|
|
|
} |
|
347
|
|
|
break; |
|
348
|
|
|
|
|
349
|
|
|
case ($srcClass == 'Tag'): |
|
350
|
|
|
if ($navigationPropName == 'Posts') { |
|
351
|
|
|
$query = "SELECT p . *" |
|
352
|
|
|
." FROM wp_posts AS p" |
|
353
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
354
|
|
|
." ON p.ID = tr.object_id" |
|
355
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
356
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
357
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->TagID" |
|
358
|
|
|
." AND p.post_type = 'post'" |
|
359
|
|
|
." AND p.post_status = 'publish'"; |
|
360
|
|
|
if ($filter !== null) { |
|
361
|
|
|
$query .= " AND $filter"; |
|
362
|
|
|
} |
|
363
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
364
|
|
|
if ($stmt === false) { |
|
365
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
$result = $this->_serializePosts($stmt); |
|
369
|
|
|
} else { |
|
370
|
|
|
die('Tag does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
371
|
|
|
} |
|
372
|
|
|
break; |
|
373
|
|
|
|
|
374
|
|
|
case ($srcClass == 'Category'): |
|
375
|
|
|
if ($navigationPropName == 'Posts') { |
|
376
|
|
|
$query = "SELECT p . *" |
|
377
|
|
|
." FROM wp_posts AS p" |
|
378
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
379
|
|
|
." ON p.ID = tr.object_id" |
|
380
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
381
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
382
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->CategoryID" |
|
383
|
|
|
." AND p.post_type = 'post'" |
|
384
|
|
|
." AND p.post_status = 'publish'"; |
|
385
|
|
|
if ($filter !== null) { |
|
386
|
|
|
$query .= " AND $filter"; |
|
387
|
|
|
} |
|
388
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
389
|
|
|
if ($stmt === false) { |
|
390
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
$result = $this->_serializePosts($stmt); |
|
394
|
|
|
} else { |
|
395
|
|
|
die('Category does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
396
|
|
|
} |
|
397
|
|
|
break; |
|
398
|
|
|
|
|
399
|
|
|
case ($srcClass == 'Comment'): |
|
400
|
|
|
die('Comment does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
401
|
|
|
break; |
|
402
|
|
|
|
|
403
|
|
|
case ($srcClass == 'User'): |
|
404
|
|
|
if ($navigationPropName == 'Posts') { |
|
405
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
|
406
|
|
|
." wp_posts.post_type = 'post'" |
|
407
|
|
|
." AND wp_posts.post_status = 'publish'" |
|
408
|
|
|
." AND wp_posts.post_author = $sourceEntityInstance->UserID"; |
|
409
|
|
|
if ($filter !== null) { |
|
410
|
|
|
$query .= " AND $filter"; |
|
411
|
|
|
} |
|
412
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
413
|
|
|
if ($stmt === false) { |
|
414
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
$result = $this->_serializePosts($stmt); |
|
418
|
|
|
} elseif ($navigationPropName == 'Comments') { |
|
419
|
|
|
$query = "SELECT * FROM `wp_comments`" |
|
420
|
|
|
." WHERE comment_approved = 1" |
|
421
|
|
|
." AND wp_comments.user_id = $sourceEntityInstance->UserID"; |
|
422
|
|
|
if ($filter !== null) { |
|
423
|
|
|
$query .= " AND $filter"; |
|
424
|
|
|
} |
|
425
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
426
|
|
|
if ($stmt === false) { |
|
427
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
|
$result = $this->_serializeComments($stmt); |
|
431
|
|
|
} else { |
|
432
|
|
|
die('User does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
433
|
|
|
} |
|
434
|
|
|
break; |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
mysql_free_result($stmt); |
|
|
|
|
|
|
438
|
|
|
return $result; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* Gets a related entity instance from an entity set identifed by a key |
|
443
|
|
|
* |
|
444
|
|
|
* @param ResourceSet $sourceResourceSet The entity set related to |
|
445
|
|
|
* the entity to be fetched. |
|
446
|
|
|
* @param object $sourceEntityInstance The related entity instance. |
|
447
|
|
|
* @param ResourceSet $targetResourceSet The entity set from which |
|
448
|
|
|
* entity needs to be fetched. |
|
449
|
|
|
* @param ResourceProperty $targetProperty The metadata of the target |
|
450
|
|
|
* property. |
|
451
|
|
|
* @param KeyDescriptor $keyDescriptor The key to identify the entity |
|
452
|
|
|
* to be fetched. |
|
453
|
|
|
* |
|
454
|
|
|
* @return object|null Returns entity instance if found else null |
|
455
|
|
|
*/ |
|
456
|
|
|
public function getResourceFromRelatedResourceSet(ResourceSet $sourceResourceSet, |
|
457
|
|
|
$sourceEntityInstance, |
|
458
|
|
|
ResourceSet $targetResourceSet, |
|
459
|
|
|
ResourceProperty $targetProperty, |
|
460
|
|
|
KeyDescriptor $keyDescriptor |
|
461
|
|
|
) { |
|
462
|
|
|
$result = array(); |
|
463
|
|
|
$srcClass = get_class($sourceEntityInstance); |
|
464
|
|
|
$navigationPropName = $targetProperty->getName(); |
|
465
|
|
|
|
|
466
|
|
|
$keys = array(); |
|
467
|
|
|
$namedKeyValues = $keyDescriptor->getValidatedNamedValues(); |
|
468
|
|
|
foreach ($namedKeyValues as $key => $value) { |
|
469
|
|
|
$keys[] = "$key = '$value[0]' "; |
|
470
|
|
|
} |
|
471
|
|
|
$conditionStr = implode(' AND ', $keys); |
|
|
|
|
|
|
472
|
|
|
|
|
473
|
|
|
switch (true) { |
|
474
|
|
|
case ($srcClass == 'Post'): |
|
475
|
|
|
if ($navigationPropName == 'Tags') { |
|
476
|
|
|
$query = "SELECT t.*, tt.description" |
|
477
|
|
|
." FROM wp_terms AS t" |
|
478
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
479
|
|
|
." ON tt.term_id = t.term_id" |
|
480
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
481
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
482
|
|
|
." WHERE tt.taxonomy IN ('post_tag')" |
|
483
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)" |
|
484
|
|
|
." AND tt.term_id = " . $namedKeyValues['TagID'][0]; |
|
485
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
486
|
|
|
$result = $this->_serializeTags($stmt); |
|
487
|
|
|
} elseif ($navigationPropName == 'Categories') { |
|
488
|
|
|
$query = "SELECT t.*, tt.description" |
|
489
|
|
|
." FROM wp_terms AS t" |
|
490
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
491
|
|
|
." ON tt.term_id = t.term_id" |
|
492
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
493
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
494
|
|
|
." WHERE tt.taxonomy IN ('category')" |
|
495
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)" |
|
496
|
|
|
." AND tt.term_id = " . $namedKeyValues['CategoryID'][0]; |
|
497
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
498
|
|
|
$result = $this->_serializeCategories($stmt); |
|
499
|
|
|
} else if ($navigationPropName == 'Comments') { |
|
500
|
|
|
$query = "SELECT * FROM `wp_comments`" |
|
501
|
|
|
." WHERE comment_approved = 1" |
|
502
|
|
|
." AND comment_post_ID = $sourceEntityInstance->PostID" |
|
503
|
|
|
." AND comment_ID = " . $namedKeyValues['CommentID'][0]; |
|
504
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
505
|
|
|
$result = $this->_serializeComments($stmt); |
|
506
|
|
|
} else { |
|
507
|
|
|
die('Post does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
508
|
|
|
} |
|
509
|
|
|
break; |
|
510
|
|
|
|
|
511
|
|
|
case ($srcClass == 'Tag'): |
|
512
|
|
|
if ($navigationPropName == 'Posts') { |
|
513
|
|
|
$query = "SELECT p . *" |
|
514
|
|
|
." FROM wp_posts AS p" |
|
515
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
516
|
|
|
." ON p.ID = tr.object_id" |
|
517
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
518
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
519
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->TagID" |
|
520
|
|
|
." AND p.post_type = 'post'" |
|
521
|
|
|
." AND p.post_status = 'publish'" |
|
522
|
|
|
." AND p.ID = " . $namedKeyValues['PostID'][0]; |
|
523
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
524
|
|
|
$result = $this->_serializePosts($stmt); |
|
525
|
|
|
} else { |
|
526
|
|
|
die('Tag does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
527
|
|
|
} |
|
528
|
|
|
break; |
|
529
|
|
|
|
|
530
|
|
|
case ($srcClass == 'Category'): |
|
531
|
|
|
if ($navigationPropName == 'Posts') { |
|
532
|
|
|
$query = "SELECT p . *" |
|
533
|
|
|
." FROM wp_posts AS p" |
|
534
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
|
535
|
|
|
." ON p.ID = tr.object_id" |
|
536
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
|
537
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
|
538
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->CategoryID" |
|
539
|
|
|
." AND p.post_type = 'post'" |
|
540
|
|
|
." AND p.post_status = 'publish'" |
|
541
|
|
|
." AND p.ID = " . $namedKeyValues['PostID'][0]; |
|
542
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
543
|
|
|
$result = $this->_serializePosts($stmt); |
|
544
|
|
|
} else { |
|
545
|
|
|
die('Category does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
546
|
|
|
} |
|
547
|
|
|
break; |
|
548
|
|
|
|
|
549
|
|
|
case ($srcClass == 'Comment'): |
|
550
|
|
|
die('Comment does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
551
|
|
|
break; |
|
552
|
|
|
|
|
553
|
|
|
case ($srcClass == 'User'): |
|
554
|
|
|
if ($navigationPropName == 'Posts') { |
|
555
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
|
556
|
|
|
." wp_posts.post_type = 'post'" |
|
557
|
|
|
." AND wp_posts.post_status = 'publish'" |
|
558
|
|
|
." AND wp_posts.post_author = $sourceEntityInstance->UserID" |
|
559
|
|
|
." AND wp_posts.ID = " . $namedKeyValues['PostID'][0]; |
|
560
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
561
|
|
|
$result = $this->_serializePosts($stmt); |
|
562
|
|
|
} elseif ($navigationPropName == 'Comments') { |
|
563
|
|
|
$query = "SELECT * FROM `wp_comments`" |
|
564
|
|
|
." WHERE comment_approved = 1" |
|
565
|
|
|
." AND wp_comments.user_id = $sourceEntityInstance->UserID" |
|
566
|
|
|
." AND wp_comments.comment_ID = " . $namedKeyValues['CommentID'][0]; |
|
567
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
568
|
|
|
$result = $this->_serializeComments($stmt); |
|
569
|
|
|
} else { |
|
570
|
|
|
die('User does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
571
|
|
|
} |
|
572
|
|
|
break; |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
mysql_free_result($stmt); |
|
|
|
|
|
|
576
|
|
|
return empty($result) ? null : $result[0]; |
|
577
|
|
|
} |
|
578
|
|
|
/** |
|
579
|
|
|
* Get related resource for a resource |
|
580
|
|
|
* |
|
581
|
|
|
* @param ResourceSet $sourceResourceSet The source resource set |
|
582
|
|
|
* @param mixed $sourceEntityInstance The source resource |
|
583
|
|
|
* @param ResourceSet $targetResourceSet The resource set of |
|
584
|
|
|
* the navigation property |
|
585
|
|
|
* @param ResourceProperty $targetProperty The navigation property to be |
|
586
|
|
|
* retrieved |
|
587
|
|
|
* |
|
588
|
|
|
* @return object|null The related resource if exists else null |
|
589
|
|
|
*/ |
|
590
|
|
|
public function getRelatedResourceReference(ResourceSet $sourceResourceSet, |
|
591
|
|
|
$sourceEntityInstance, |
|
592
|
|
|
ResourceSet $targetResourceSet, |
|
593
|
|
|
ResourceProperty $targetProperty |
|
594
|
|
|
) { |
|
595
|
|
|
$result = null; |
|
596
|
|
|
$srcClass = get_class($sourceEntityInstance); |
|
597
|
|
|
$navigationPropName = $targetProperty->getName(); |
|
598
|
|
|
|
|
599
|
|
|
switch (true) { |
|
600
|
|
|
case ($srcClass == 'Post'): |
|
601
|
|
|
if ($navigationPropName == 'User') { |
|
602
|
|
|
$query = "SELECT * FROM `wp_users` WHERE ID = $sourceEntityInstance->Author"; |
|
603
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
604
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
605
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
606
|
|
|
$result = $this->_serializeUser($data); |
|
607
|
|
|
if ($stmt === false) { |
|
608
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
612
|
|
|
$result = null; |
|
613
|
|
|
} |
|
614
|
|
|
} else { |
|
615
|
|
|
die('Post does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
616
|
|
|
} |
|
617
|
|
|
break; |
|
618
|
|
|
|
|
619
|
|
|
case ($srcClass == 'Comment'): |
|
620
|
|
|
if ($navigationPropName == 'User') { |
|
621
|
|
|
$query = "SELECT * FROM `wp_users` WHERE ID = $sourceEntityInstance->UserID"; |
|
622
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
623
|
|
|
if ($stmt === false) { |
|
624
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
628
|
|
|
$result = null; |
|
|
|
|
|
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
632
|
|
|
$result = $this->_serializeUser($data); |
|
633
|
|
|
|
|
634
|
|
|
} elseif ($navigationPropName == 'Post') { |
|
635
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
|
636
|
|
|
." wp_posts.post_type = 'post'" |
|
637
|
|
|
." AND wp_posts.post_status = 'publish'" |
|
638
|
|
|
." AND wp_posts.ID = $sourceEntityInstance->PostID"; |
|
639
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
|
|
640
|
|
|
if ($stmt === false) { |
|
641
|
|
|
die(mysql_error()); |
|
|
|
|
|
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
if (!mysql_num_rows($stmt)) { |
|
|
|
|
|
|
645
|
|
|
$result = null; |
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
$data = mysql_fetch_assoc($stmt); |
|
|
|
|
|
|
649
|
|
|
$result = $this->_serializePost($data); |
|
650
|
|
|
} else { |
|
651
|
|
|
die('Comment does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
|
|
652
|
|
|
} |
|
653
|
|
|
break; |
|
654
|
|
|
} |
|
655
|
|
|
|
|
656
|
|
|
mysql_free_result($stmt); |
|
|
|
|
|
|
657
|
|
|
return $result; |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** |
|
661
|
|
|
* Serialize the mysql result array into Post objects |
|
662
|
|
|
* |
|
663
|
|
|
* @param resource $result result of the mysql query |
|
664
|
|
|
* |
|
665
|
|
|
* @return array(Object) |
|
666
|
|
|
*/ |
|
667
|
|
|
private function _serializePosts($result) |
|
668
|
|
|
{ |
|
669
|
|
|
$posts = array(); |
|
670
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
|
|
|
|
|
|
671
|
|
|
$posts[] = $this->_serializePost($record); |
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
return $posts; |
|
675
|
|
|
} |
|
676
|
|
|
|
|
677
|
|
|
/** |
|
678
|
|
|
* Serialize the mysql row into Post object |
|
679
|
|
|
* |
|
680
|
|
|
* @param array $record each post row |
|
681
|
|
|
* |
|
682
|
|
|
* @return Post |
|
683
|
|
|
*/ |
|
684
|
|
|
private function _serializePost($record) |
|
685
|
|
|
{ |
|
686
|
|
|
$post = new Post(); |
|
687
|
|
|
$post->PostID = $record['ID']; |
|
688
|
|
|
$post->Author = $record['post_author']; |
|
689
|
|
|
|
|
690
|
|
|
if (!is_null($record['post_date'])) { |
|
691
|
|
|
$dateTime = new DateTime($record['post_date']); |
|
692
|
|
|
$post->Date = $dateTime->format('Y-m-d\TH:i:s'); |
|
693
|
|
|
} else { |
|
694
|
|
|
$post->Date = null; |
|
695
|
|
|
} |
|
696
|
|
|
|
|
697
|
|
|
if (!is_null($record['post_date_gmt'])) { |
|
698
|
|
|
$dateTime = new DateTime($record['post_date_gmt']); |
|
699
|
|
|
$post->DateGmt = $dateTime->format('Y-m-d\TH:i:s'); |
|
700
|
|
|
} else { |
|
701
|
|
|
$post->DateGmt = null; |
|
702
|
|
|
} |
|
703
|
|
|
|
|
704
|
|
|
$post->Content = $record['post_content']; |
|
705
|
|
|
$post->Title = $record['post_title']; |
|
706
|
|
|
$post->Excerpt = $record['post_excerpt']; |
|
707
|
|
|
$post->Status = $record['post_status']; |
|
708
|
|
|
$post->CommentStatus = $record['comment_status']; |
|
709
|
|
|
$post->PingStatus = $record['ping_status']; |
|
710
|
|
|
$post->Password = $record['post_password']; |
|
711
|
|
|
$post->Name = $record['post_name']; |
|
712
|
|
|
$post->ToPing = $record['to_ping']; |
|
713
|
|
|
$post->Pinged = $record['pinged']; |
|
714
|
|
|
|
|
715
|
|
|
if (!is_null($record['post_modified'])) { |
|
716
|
|
|
$dateTime = new DateTime($record['post_modified']); |
|
717
|
|
|
$post->Modified = $dateTime->format('Y-m-d\TH:i:s'); |
|
718
|
|
|
} else { |
|
719
|
|
|
$post->Modified = null; |
|
720
|
|
|
} |
|
721
|
|
|
|
|
722
|
|
|
if (!is_null($record['post_modified_gmt'])) { |
|
723
|
|
|
$dateTime = new DateTime($record['post_modified_gmt']); |
|
724
|
|
|
$post->ModifiedGmt = $dateTime->format('Y-m-d\TH:i:s'); |
|
725
|
|
|
} else { |
|
726
|
|
|
$post->ModifiedGmt = null; |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
$post->ContentFiltered = $record['post_content_filtered']; |
|
730
|
|
|
$post->ParentID = $record['post_parent']; |
|
731
|
|
|
$post->Guid = $record['guid']; |
|
732
|
|
|
$post->MenuOrder = $record['menu_order']; |
|
733
|
|
|
$post->Type = $record['post_type']; |
|
734
|
|
|
$post->MimeType = $record['post_mime_type']; |
|
735
|
|
|
$post->CommentCount = $record['comment_count']; |
|
736
|
|
|
return $post; |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
/** |
|
740
|
|
|
* Serialize the mysql result array into Tag objects |
|
741
|
|
|
* |
|
742
|
|
|
* @param resource $result result of the mysql query |
|
743
|
|
|
* |
|
744
|
|
|
* @return array(Object) |
|
745
|
|
|
*/ |
|
746
|
|
|
private function _serializeTags($result) |
|
747
|
|
|
{ |
|
748
|
|
|
$tags = array(); |
|
749
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
|
|
|
|
|
|
750
|
|
|
$tags[] = $this->_serializeTag($record); |
|
751
|
|
|
} |
|
752
|
|
|
|
|
753
|
|
|
return $tags; |
|
754
|
|
|
} |
|
755
|
|
|
|
|
756
|
|
|
/** |
|
757
|
|
|
* Serialize the mysql row into Tag object |
|
758
|
|
|
* |
|
759
|
|
|
* @param array $record each tag row |
|
760
|
|
|
* |
|
761
|
|
|
* @return Tag |
|
762
|
|
|
*/ |
|
763
|
|
|
private function _serializeTag($record) |
|
764
|
|
|
{ |
|
765
|
|
|
$tag = new Tag(); |
|
766
|
|
|
$tag->TagID = $record['term_id']; |
|
767
|
|
|
$tag->Name = $record['name']; |
|
768
|
|
|
$tag->Slug = $record['slug']; |
|
769
|
|
|
$tag->Description = $record['description']; |
|
770
|
|
|
return $tag; |
|
771
|
|
|
} |
|
772
|
|
|
|
|
773
|
|
|
/** |
|
774
|
|
|
* Serialize the mysql result array into Category objects |
|
775
|
|
|
* |
|
776
|
|
|
* @param resource $result result of the mysql query |
|
777
|
|
|
* |
|
778
|
|
|
* @return array(Object) |
|
779
|
|
|
*/ |
|
780
|
|
|
private function _serializeCategories($result) |
|
781
|
|
|
{ |
|
782
|
|
|
$cats = array(); |
|
783
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
|
|
|
|
|
|
784
|
|
|
$cats[] = $this->_serializeCategory($record); |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
return $cats; |
|
788
|
|
|
} |
|
789
|
|
|
|
|
790
|
|
|
/** |
|
791
|
|
|
* Serialize the mysql row into Category object |
|
792
|
|
|
* |
|
793
|
|
|
* @param array $record each category row |
|
794
|
|
|
* |
|
795
|
|
|
* @return Category |
|
796
|
|
|
*/ |
|
797
|
|
|
private function _serializeCategory($record) |
|
798
|
|
|
{ |
|
799
|
|
|
$cat = new Category(); |
|
800
|
|
|
$cat->CategoryID = $record['term_id']; |
|
801
|
|
|
$cat->Name = $record['name']; |
|
802
|
|
|
$cat->Slug = $record['slug']; |
|
803
|
|
|
$cat->Description = $record['description']; |
|
804
|
|
|
return $cat; |
|
805
|
|
|
} |
|
806
|
|
|
|
|
807
|
|
|
/** |
|
808
|
|
|
* Serialize the mysql result array into Comment objects |
|
809
|
|
|
* |
|
810
|
|
|
* @param resource $result mysql query result |
|
811
|
|
|
* |
|
812
|
|
|
* @return array(Object) |
|
813
|
|
|
*/ |
|
814
|
|
|
private function _serializeComments($result) |
|
815
|
|
|
{ |
|
816
|
|
|
$comments = array(); |
|
817
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
|
|
|
|
|
|
818
|
|
|
$comments[] = $this->_serializeComment($record); |
|
819
|
|
|
} |
|
820
|
|
|
|
|
821
|
|
|
return $comments; |
|
822
|
|
|
} |
|
823
|
|
|
|
|
824
|
|
|
/** |
|
825
|
|
|
* Serialize the mysql row into Comment object |
|
826
|
|
|
* |
|
827
|
|
|
* @param array $record each comment row |
|
828
|
|
|
* |
|
829
|
|
|
* @return Comment |
|
830
|
|
|
*/ |
|
831
|
|
|
private function _serializeComment($record) |
|
832
|
|
|
{ |
|
833
|
|
|
$comment = new Comment(); |
|
834
|
|
|
$comment->CommentID = $record['comment_ID']; |
|
835
|
|
|
$comment->PostID = $record['comment_post_ID']; |
|
836
|
|
|
$comment->Author = $record['comment_author']; |
|
837
|
|
|
$comment->AuthorEmail = $record['comment_author_email']; |
|
838
|
|
|
$comment->AuthorUrl = $record['comment_author_url']; |
|
839
|
|
|
$comment->AuthorIp = $record['comment_author_IP']; |
|
840
|
|
|
|
|
841
|
|
|
if (!is_null($record['comment_date'])) { |
|
842
|
|
|
$dateTime = new DateTime($record['comment_date']); |
|
843
|
|
|
$comment->Date = $dateTime->format('Y-m-d\TH:i:s'); |
|
844
|
|
|
} else { |
|
845
|
|
|
$comment->Date = null; |
|
846
|
|
|
} |
|
847
|
|
|
|
|
848
|
|
|
if (!is_null($record['comment_date_gmt'])) { |
|
849
|
|
|
$dateTime = new DateTime($record['comment_date_gmt']); |
|
850
|
|
|
$comment->DateGmt = $dateTime->format('Y-m-d\TH:i:s'); |
|
851
|
|
|
} else { |
|
852
|
|
|
$comment->DateGmt = null; |
|
853
|
|
|
} |
|
854
|
|
|
|
|
855
|
|
|
$comment->Content = $record['comment_content']; |
|
856
|
|
|
$comment->Karma = $record['comment_karma']; |
|
857
|
|
|
$comment->Approved = $record['comment_approved']; |
|
858
|
|
|
$comment->Agent = $record['comment_agent']; |
|
859
|
|
|
$comment->Type = $record['comment_type']; |
|
860
|
|
|
$comment->ParentID = $record['comment_parent']; |
|
861
|
|
|
$comment->UserID = $record['user_id']; |
|
862
|
|
|
return $comment; |
|
863
|
|
|
} |
|
864
|
|
|
|
|
865
|
|
|
/** |
|
866
|
|
|
* Serialize the mysql result array into User objects |
|
867
|
|
|
* |
|
868
|
|
|
* @param resource $result result of the mysql query |
|
869
|
|
|
* |
|
870
|
|
|
* @return array(Object) |
|
871
|
|
|
*/ |
|
872
|
|
|
private function _serializeUsers($result) |
|
873
|
|
|
{ |
|
874
|
|
|
$users = array(); |
|
875
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
|
|
|
|
|
|
876
|
|
|
$users[] = $this->_serializeUser($record); |
|
877
|
|
|
} |
|
878
|
|
|
|
|
879
|
|
|
return $users; |
|
880
|
|
|
} |
|
881
|
|
|
|
|
882
|
|
|
/** |
|
883
|
|
|
* Serialize the mysql row into User object |
|
884
|
|
|
* |
|
885
|
|
|
* @param array $record each user row |
|
886
|
|
|
* |
|
887
|
|
|
* @return User |
|
888
|
|
|
*/ |
|
889
|
|
|
private function _serializeUser($record) |
|
890
|
|
|
{ |
|
891
|
|
|
$user = new User(); |
|
892
|
|
|
$user->UserID = $record['ID']; |
|
893
|
|
|
$user->Login = $record['user_login']; |
|
894
|
|
|
$user->Nicename = $record['user_nicename']; |
|
895
|
|
|
$user->Email = $record['user_email']; |
|
896
|
|
|
$user->Url = $record['user_url']; |
|
897
|
|
|
|
|
898
|
|
|
if (!is_null($record['user_registered'])) { |
|
899
|
|
|
$dateTime = new DateTime($record['user_registered']); |
|
900
|
|
|
$user->Registered = $dateTime->format('Y-m-d\TH:i:s'); |
|
901
|
|
|
} else { |
|
902
|
|
|
$user->Registered = null; |
|
903
|
|
|
} |
|
904
|
|
|
|
|
905
|
|
|
$user->Status = $record['user_status']; |
|
906
|
|
|
$user->DisplayName = $record['display_name']; |
|
907
|
|
|
return $user; |
|
908
|
|
|
} |
|
909
|
|
|
|
|
910
|
|
|
|
|
911
|
|
|
} |
|
912
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.