| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.0 Free | |
| 4 | + * @version 2.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2024 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FireBox\Core\FB; |
| @@ -21,37 +21,8 @@ | ||
| 21 | 21 | |
| 22 | 22 | class Boxes |
| 23 | 23 | { |
| 24 | 24 | /** |
| 25 | - * A box instance | |
| 26 | - * | |
| 27 | - * @var Box | |
| 28 | - */ | |
| 29 | - protected $box; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Factory | |
| 33 | - * | |
| 34 | - * @var Factory | |
| 35 | - */ | |
| 36 | - protected $factory; | |
| 37 | - | |
| 38 | - public function __construct($box = null, $factory = null) | |
| 39 | - { | |
| 40 | - if (!$factory) | |
| 41 | - { | |
| 42 | - $factory = new \FPFramework\Base\Factory(); | |
| 43 | - } | |
| 44 | - $this->factory = $factory; | |
| 45 | - | |
| 46 | - if (!$box) | |
| 47 | - { | |
| 48 | - $box = new \FireBox\Core\FB\Box(null, $this->factory); | |
| 49 | - } | |
| 50 | - $this->box = $box; | |
| 51 | - } | |
| 52 | - | |
| 53 | - /** | |
| 54 | 25 | * Render boxes |
| 55 | 26 | * |
| 56 | 27 | * @return string |
| 57 | 28 | */ |
| @@ -56,16 +27,14 @@ | ||
| 56 | 27 | * @return string |
| 57 | 28 | */ |
| 58 | 29 | public function render() |
| 59 | 30 | { |
| 60 | - $boxes_query = BoxHelper::getAllBoxesWPQuery(); | |
| 61 | - | |
| 62 | - if (!method_exists($boxes_query, 'have_posts') || (method_exists($boxes_query, 'have_posts') && !$boxes_query->have_posts())) | |
| 31 | + if (!$boxes = BoxHelper::getAllBoxes()) | |
| 63 | 32 | { |
| 64 | 33 | return; |
| 65 | - } | |
| 34 | + } | |
| 66 | 35 | |
| 67 | - return $this->renderAll($boxes_query); | |
| 36 | + return $this->renderAll($boxes); | |
| 68 | 37 | } |
| 69 | 38 | |
| 70 | 39 | /** |
| 71 | 40 | * Renders all boxes |
| @@ -77,23 +46,29 @@ | ||
| 77 | 46 | public function renderAll($boxes) |
| 78 | 47 | { |
| 79 | 48 | $html = ''; |
| 80 | 49 | |
| 81 | - // handle WP_Query boxes loop | |
| 82 | - if (isset($boxes->posts)) | |
| 50 | + if ($boxes instanceof \WP_Query) | |
| 83 | 51 | { |
| 84 | - foreach ($boxes->posts as $box) | |
| 52 | + if (!$boxes->have_posts()) | |
| 85 | 53 | { |
| 54 | + return; | |
| 55 | + } | |
| 56 | + | |
| 57 | + while ($boxes->have_posts()) | |
| 58 | + { | |
| 86 | 59 | $boxes->the_post(); |
| 87 | 60 | |
| 88 | - $this->prepare($box); | |
| 61 | + global $post; | |
| 89 | 62 | |
| 90 | - $html .= $this->get_output($box); | |
| 63 | + $this->prepare($post); | |
| 64 | + | |
| 65 | + $html .= $this->get_output($post); | |
| 91 | 66 | } |
| 92 | - wp_reset_query(); | |
| 67 | + | |
| 68 | + wp_reset_postdata(); | |
| 93 | 69 | } |
| 94 | - else | |
| 95 | - // handle boxes array | |
| 70 | + else if (is_array($boxes)) | |
| 96 | 71 | { |
| 97 | 72 | foreach ($boxes as $box) |
| 98 | 73 | { |
| 99 | 74 | $this->prepare($box); |
| @@ -100,9 +75,9 @@ | ||
| 100 | 75 | |
| 101 | 76 | $html .= $this->get_output($box); |
| 102 | 77 | } |
| 103 | 78 | } |
| 104 | - | |
| 79 | + | |
| 105 | 80 | return $html; |
| 106 | 81 | } |
| 107 | 82 | |
| 108 | 83 | /** |
| @@ -137,34 +112,7 @@ | ||
| 137 | 112 | { |
| 138 | 113 | return ''; |
| 139 | 114 | } |
| 140 | 115 | |
| 141 | - return $this->box->render($box); | |
| 142 | - } | |
| 143 | - | |
| 144 | - /** | |
| 145 | - * Return the box | |
| 146 | - * | |
| 147 | - * @return Box | |
| 148 | - */ | |
| 149 | - public function getBox() | |
| 150 | - { | |
| 151 | - return $this->box; | |
| 152 | - } | |
| 153 | - | |
| 154 | - /** | |
| 155 | - * Set the box | |
| 156 | - * | |
| 157 | - * @param Box $box | |
| 158 | - * | |
| 159 | - * @return Box | |
| 160 | - */ | |
| 161 | - public function setBox($box) | |
| 162 | - { | |
| 163 | - if (!$box) | |
| 164 | - { | |
| 165 | - return; | |
| 166 | - } | |
| 167 | - | |
| 168 | - $this->box = $box; | |
| 116 | + return firebox()->box->setBox($box)->render(); | |
| 169 | 117 | } |
| 170 | 118 | } |