1
|
<?php
|
2
|
|
3
|
defined( '_JEXEC' ) or die( 'Restricted access' );
|
4
|
|
5
|
jimport('joomla.database.database');
|
6
|
jimport('joomla.environment.request');
|
7
|
jimport('joomla.error.log');
|
8
|
|
9
|
function OpenaireBuildRoute(&$query) {
|
10
|
$segments = array();
|
11
|
$cache =& JFactory :: getCache();
|
12
|
$log =& JLog :: getInstance();
|
13
|
|
14
|
if (isset($query['view']) && ($query['view'] != '')) {
|
15
|
$segments[0] = $query['view'];
|
16
|
unset($query['view']);
|
17
|
} else
|
18
|
$segments[0] = 'default';
|
19
|
if (isset($query['layout']) && ($query['layout'] != '')) {
|
20
|
$segments[1] = $query['layout'];
|
21
|
unset($query['layout']);
|
22
|
} else
|
23
|
$segments[1] = 'default';
|
24
|
if (isset($query['Itemid']) && ($query['Itemid'] != '')) {
|
25
|
$segments[2] = $query['Itemid'];
|
26
|
unset($query['Itemid']);
|
27
|
} else
|
28
|
$segments[2] = 0;
|
29
|
|
30
|
if (JDEBUG)
|
31
|
$log -> addEntry(array('level' => 'debug', 'comment' => ('Building route view = ' . $segments[0] . ', layout = ' . $segments[1] . ', Itemid = ' . $segments[2])));
|
32
|
|
33
|
if (($segments[0] == 'default') && ($segments[2] != 0))
|
34
|
list($segments[0], $segments[1]) = $cache -> call('_resolveViewAndLayoutByItemId', $segments[2]);
|
35
|
else if (($segments[0] != 'default') && ($segments[2] == 0))
|
36
|
$segments[2] = $cache -> call('_resolveItemIdByViewAndLayout', $segments[0], $segments[1]);
|
37
|
|
38
|
if (JDEBUG)
|
39
|
$log -> addEntry(array('level' => 'debug', 'comment' => ('Built route view = ' . $segments[0] . ', layout = ' . $segments[1] . ', Itemid = ' . $segments[2])));
|
40
|
|
41
|
return $segments;
|
42
|
}
|
43
|
|
44
|
function OpenaireParseRoute($segments) {
|
45
|
$query = array();
|
46
|
|
47
|
if (JRequest::getVar('option', '', 'post') != '' && JRequest::getVar('option', '', 'post') != 'com_openaire') {
|
48
|
foreach (array('option', 'view', 'itemId', 'task', 'layout') as $param) {
|
49
|
$query[$param] = JRequest::getVar($param, '', 'post');
|
50
|
}
|
51
|
} else {
|
52
|
$cache =& JFactory :: getCache();
|
53
|
$log =& JLog :: getInstance();
|
54
|
|
55
|
if (isset($segments[0]) && ($segments[0] != ''))
|
56
|
$query['view'] = $segments[0];
|
57
|
else
|
58
|
$query['view'] = 'default';
|
59
|
if (isset($segments[1]) && ($segments[1] != ''))
|
60
|
$query['layout'] = $segments[1];
|
61
|
else
|
62
|
$query['layout'] = 'default';
|
63
|
if (isset($segments[2]) && ($segments[2] != ''))
|
64
|
$query['Itemid'] = $segments[2];
|
65
|
else
|
66
|
$query['Itemid'] = 0;
|
67
|
|
68
|
if (JDEBUG)
|
69
|
$log -> addEntry(array('level' => 'debug', 'comment' => ('Parsing route view = ' . $query['view'] . ', layout = ' . $query['layout'] . ', Itemid = ' . $query['Itemid'])));
|
70
|
|
71
|
if (($query['view'] == 'default') && ($query['Itemid'] != 0))
|
72
|
list($query['view'], $query['layout']) = $cache -> call('_resolveViewAndLayoutByItemId', $query['Itemid']);
|
73
|
else if (($query['view'] != 'default') && ($query['Itemid'] == 0))
|
74
|
$query['Itemid'] = $cache -> call('_resolveItemIdByViewAndLayout', $query['view'], $query['layout']);
|
75
|
|
76
|
if (JDEBUG)
|
77
|
$log -> addEntry(array('level' => 'debug', 'comment' => ('Parsed route view = ' . $query['view'] . ', layout = ' . $query['layout'] . ', Itemid = ' . $query['Itemid'])));
|
78
|
|
79
|
JRequest :: setVar('option', 'com_openaire');
|
80
|
JRequest :: setVar('view', $query['view']);
|
81
|
JRequest :: setVar('layout', $query['layout']);
|
82
|
JRequest :: setVar('Itemid', $query['Itemid']);
|
83
|
}
|
84
|
|
85
|
return $query;
|
86
|
}
|
87
|
|
88
|
function _resolveViewAndLayoutByItemId($itemId) {
|
89
|
if (JDEBUG)
|
90
|
JLog :: getInstance() -> addEntry(array('level' => 'debug', 'comment' => 'Resolving view and layout by Itemid = ' . $itemId));
|
91
|
|
92
|
$view = 'default';
|
93
|
$layout = 'default';
|
94
|
$db =& JFactory :: getDBO();
|
95
|
|
96
|
$db -> setQuery('SELECT ' . $db -> nameQuote('link') . ' FROM ' . $db -> nameQuote('#__menu') . ' WHERE ' . $db -> nameQuote('id') . ' = ' . $db -> quote($itemId));
|
97
|
if (preg_match("/index\.php\?(.+)/", $db -> loadResult(), $matches)) { // query string found
|
98
|
foreach (explode('&', $matches[0]) as $parameter) {
|
99
|
list($name, $value) = explode('=', $parameter);
|
100
|
switch ($name) {
|
101
|
case 'view':
|
102
|
$view = $value;
|
103
|
break;
|
104
|
case 'layout':
|
105
|
$layout = $value;
|
106
|
}
|
107
|
}
|
108
|
}
|
109
|
|
110
|
return array($view, $layout);
|
111
|
}
|
112
|
|
113
|
function _resolveItemIdByViewAndLayout($view, $layout = 'default') {
|
114
|
if (JDEBUG)
|
115
|
JLog :: getInstance() -> addEntry(array('level' => 'debug', 'comment' => ('Resolving Itemid by view = ' . $view . ' and layout = ' . $layout)));
|
116
|
|
117
|
$itemId = 0;
|
118
|
$db =& JFactory :: getDBO();
|
119
|
|
120
|
$db -> setQuery('SELECT ' . $db -> nameQuote('id') . ' FROM ' . $db -> nameQuote('#__menu') . ' WHERE ' . $db -> nameQuote('link') . ' = ' . $db -> quote('index.php?option=com_openaire&view=' . $view . (($layout != 'default') ? ('&layout=' . $layout) : '')));
|
121
|
$itemId = $db -> loadResult();
|
122
|
|
123
|
return $itemId;
|
124
|
}
|
125
|
|
126
|
?>
|