site.php
99 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikWP - Libraries |
| 4 | * @subpackage adapter.application |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | JLoader::import('adapter.pathway.pathway'); |
| 15 | |
| 16 | /** |
| 17 | * Class to maintain a pathway for the site client. |
| 18 | * The user's navigated path within the site application. |
| 19 | * |
| 20 | * @since 10.1.19 |
| 21 | */ |
| 22 | class JPathwaySite extends JPathway |
| 23 | { |
| 24 | /** |
| 25 | * Class constructor. |
| 26 | * |
| 27 | * @param array $options The class options. |
| 28 | */ |
| 29 | public function __construct($options = array()) |
| 30 | { |
| 31 | // add home to pathway |
| 32 | $this->addItem(__('Home'), 'index.php'); |
| 33 | |
| 34 | // extract post from current URL |
| 35 | $id = url_to_postid(JUri::current()); |
| 36 | $post = get_post($id); |
| 37 | |
| 38 | if ($post) |
| 39 | { |
| 40 | $tree = array($post); |
| 41 | |
| 42 | // get post parent |
| 43 | $post->post_parent; |
| 44 | |
| 45 | // iterate as long as we have a parent ID |
| 46 | while ($post && $post->post_parent) |
| 47 | { |
| 48 | // get parent |
| 49 | $post = get_post($post->post_parent); |
| 50 | |
| 51 | if ($post) |
| 52 | { |
| 53 | // prepend parent |
| 54 | array_unshift($tree, $post); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // get regex to extract shortcodes from post content |
| 59 | $regex = get_shortcode_regex(); |
| 60 | |
| 61 | // build tree |
| 62 | foreach ($tree as $post) |
| 63 | { |
| 64 | $parts = array(); |
| 65 | |
| 66 | if (preg_match("/$regex/s", $post->post_content, $match)) |
| 67 | { |
| 68 | // search for the component name |
| 69 | if (isset($match[2])) |
| 70 | { |
| 71 | $parts['option'] = 'com_' . $match[2]; |
| 72 | } |
| 73 | |
| 74 | // search for shortcode attributes |
| 75 | if (isset($match[3])) |
| 76 | { |
| 77 | // extract key and values from shortcode attributes |
| 78 | if (preg_match_all("/([a-z0-9_\-]+)=\"([^\"]*)\"/si", $match[3], $chunks)) |
| 79 | { |
| 80 | // iterate chunks |
| 81 | for ($i = 0; $i < count($chunks[0]); $i++) |
| 82 | { |
| 83 | // append key=val to $parts |
| 84 | $parts[trim($chunks[1][$i])] = $chunks[2][$i]; |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // build plain link |
| 91 | $link = 'index.php?' . http_build_query(array_filter($parts)); |
| 92 | |
| 93 | // add post within the pathway |
| 94 | $this->addItem($post->post_title, $link); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 |