-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.5AddOrderToJdocInclude_html.php.patch
70 lines (65 loc) · 2 KB
/
1.5AddOrderToJdocInclude_html.php.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--- libraries/joomla/document/html/html.php
+++ libraries/joomla/document/html/html.php
@@ -367,7 +367,7 @@
*/
function _parseTemplate($data)
{
- $replace = array();
+ $template_tags = array();
$matches = array();
if(preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $data, $matches))
{
@@ -377,18 +377,53 @@
$count = count($matches[1]);
+ $order_vals = $order_idxs = $order_attribs = array();
+
for($i = 0; $i < $count; $i++)
{
$attribs = JUtility::parseAttributes( $matches[2][$i] );
- $type = $matches[1][$i];
+ if (isset($attribs['order'])) {
+ $order_vals[] = (int) $attribs['order'];
+ $order_idxs[] = $i;
+ $order_attribs[] = $attribs;
+ } else {
+ $type = $matches[1][$i];
+
+ $name = isset($attribs['name']) ? $attribs['name'] : null;
+ $template_tags[$matches[0][$i]] = array('type'=>$type, 'name' => $name, 'attribs' => $attribs);
+ }
+ }
+
+ if ($order_idxs) {
+ array_multisort($order_vals, $order_idxs, $order_attribs);
+ for ($i = 0, $count = count($order_idxs); $i < $count; $i++) {
+ $j = $order_idxs[$i];
+ $type = $matches[1][$j];
- $name = isset($attribs['name']) ? $attribs['name'] : null;
- $replace[$i] = $this->getBuffer($type, $name, $attribs);
+ $attribs = $order_attribs[$i];
+ $name = isset($attribs['name']) ? $attribs['name'] : null;
+ $template_tags[$matches[0][$j]] = array('type'=>$type, 'name' => $name, 'attribs' => $attribs);
+ }
}
+ }
+
+ return $this->_renderTemplate($template_tags, $data);
+ }
+
+ /**
+ * Render pre-parsed template
+ *
+ * @return string rendered template
+ */
+ function _renderTemplate($template_tags, $data) {
+ $replace = array();
+ $with = array();
- $data = str_replace($matches[0], $replace, $data);
+ foreach($template_tags AS $jdoc => $args) {
+ $replace[] = $jdoc;
+ $with[] = $this->getBuffer($args['type'], $args['name'], $args['attribs']);
}
- return $data;
+ return str_replace($replace, $with, $data);
}
}