| 1 |
<?php |
| 2 |
|
| 3 |
namespace VisualComposer\Helpers; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) { |
| 6 |
header('Status: 403 Forbidden'); |
| 7 |
header('HTTP/1.1 403 Forbidden'); |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
use VisualComposer\Framework\Container; |
| 12 |
use VisualComposer\Framework\Illuminate\Support\Helper; |
| 13 |
|
| 14 |
class PostsGridSourcePosts extends Container implements Helper |
| 15 |
{ |
| 16 |
public function getPostsCategories() |
| 17 |
{ |
| 18 |
$args = [ |
| 19 |
'type' => 'post', |
| 20 |
'child_of' => 0, |
| 21 |
'parent' => '', |
| 22 |
'orderby' => 'parent', |
| 23 |
'order' => 'ASC', |
| 24 |
'hide_empty' => false, |
| 25 |
'hierarchical' => 1, |
| 26 |
'exclude' => '', |
| 27 |
'include' => '', |
| 28 |
'number' => '', |
| 29 |
'taxonomy' => 'category', |
| 30 |
'pad_counts' => false, |
| 31 |
|
| 32 |
]; |
| 33 |
// All this move to product |
| 34 |
$categories = get_categories($args); |
| 35 |
|
| 36 |
$result = [ |
| 37 |
[ |
| 38 |
'label' => __('All', 'visualcomposer'), |
| 39 |
'value' => '', |
| 40 |
], |
| 41 |
]; |
| 42 |
$this->getCategoryChildsFull(0, 0, $categories, 0, $result); |
| 43 |
|
| 44 |
return $result; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get lists of categories.* |
| 49 |
* |
| 50 |
* @param $parentId |
| 51 |
* @param $pos |
| 52 |
* @param array $array |
| 53 |
* @param $level |
| 54 |
* @param array $dropdown - passed by reference |
| 55 |
*/ |
| 56 |
protected function getCategoryChildsFull($parentId, $pos, $array, $level, &$dropdown) |
| 57 |
{ |
| 58 |
for ($i = $pos; $i < count($array); $i++) { |
| 59 |
if ($array[ $i ]->category_parent == $parentId) { |
| 60 |
$name = str_repeat('- ', $level) . $array[ $i ]->name; |
| 61 |
$value = $array[ $i ]->term_id; |
| 62 |
$dropdown[] = [ |
| 63 |
'label' => $name, |
| 64 |
'value' => $value, |
| 65 |
]; |
| 66 |
$this->getCategoryChildsFull($array[ $i ]->term_id, $i, $array, $level + 1, $dropdown); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|