| 1 |
<?php |
| 2 |
/* |
| 3 |
* This file is part of the ManageWP Worker plugin. |
| 4 |
* |
| 5 |
* (c) ManageWP LLC <contact@managewp.com> |
| 6 |
* |
| 7 |
* For the full copyright and license information, please view the LICENSE |
| 8 |
* file that was distributed with this source code. |
| 9 |
*/ |
| 10 |
|
| 11 |
class MWP_WordPress_Query_Post extends MWP_WordPress_Query_Abstract |
| 12 |
{ |
| 13 |
|
| 14 |
public function query(array $options = array()) |
| 15 |
{ |
| 16 |
$options += array( |
| 17 |
'query' => null, |
| 18 |
'prefixName' => '{{prefix}}', |
| 19 |
'deserialize' => array(), |
| 20 |
'tryDeserialize' => array(), |
| 21 |
'featuredImage' => 'thumbnail', |
| 22 |
'featuredImageHeight' => null, |
| 23 |
'featuredImageWidth' => null, |
| 24 |
'featuredImageCrop' => false, |
| 25 |
); |
| 26 |
|
| 27 |
$query = str_replace($options['prefixName'], $this->getDb()->prefix, $options['query']); |
| 28 |
$posts = $this->getDb()->get_results($query, ARRAY_A); |
| 29 |
$this->deserialize($posts, $options['deserialize'], $options['tryDeserialize']); |
| 30 |
$this->fillFeaturedImages($posts, $options['featuredImage'], $options['featuredImageHeight'], $options['featuredImageWidth'], $options['featuredImageCrop']); |
| 31 |
|
| 32 |
return $posts; |
| 33 |
} |
| 34 |
|
| 35 |
private function fillFeaturedImages(&$posts, $imageStyle, $imageHeight, $imageWidth, $crop) |
| 36 |
{ |
| 37 |
if (count($posts) === 0 || !$imageStyle) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if ($imageHeight || $imageWidth) { |
| 42 |
$this->context->addImageStyle($imageStyle, $imageWidth, $imageHeight, $crop); |
| 43 |
} |
| 44 |
|
| 45 |
foreach ($posts as &$post) { |
| 46 |
if (empty($post['featuredImageId'])) { |
| 47 |
continue; |
| 48 |
} |
| 49 |
$info = $this->context->getImageInfo($post['featuredImageId'], $imageStyle); |
| 50 |
if ($info === null) { |
| 51 |
continue; |
| 52 |
} |
| 53 |
$post['featuredImage'] = $info['url']; |
| 54 |
$post['featuredImageHeight'] = $info['height']; |
| 55 |
$post['featuredImageWidth'] = $info['width']; |
| 56 |
$post['featuredImageOriginal'] = $info['original']; |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|