-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmultiMenuPreload.class.php
More file actions
176 lines (174 loc) · 5.9 KB
/
multiMenuPreload.class.php
File metadata and controls
176 lines (174 loc) · 5.9 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/*
* 2011/09/09 16:45
* Multi-Menu preload for smarty insertion to theme
* copyright(c) Yoshi Sakai at Bluemoon inc 2011
* GPL ver3.0 All right reserved.
*/
if (!defined('XOOPS_ROOT_PATH')) exit();
include_once XOOPS_ROOT_PATH . '/modules/multiMenu/class/getMultiMenu.class.php';
class multiMenuPreload extends XCube_ActionFilter{
function preBlockFilter(){
$this->mRoot->mDelegateManager->add(
'Legacy_RenderSystem.SetupXoopsTpl',
array(&$this, 'menuSmartyAssign')
);
}
function menuSmartyAssign(&$xoopsTpl) {
$module_handler = & xoops_gethandler( 'module' );
$module =& $module_handler->getByDirname('multiMenu');
if ( !is_object( $module ) || !$module->getVar( 'isactive' ) ) {
return ;
}
$gmm = new getMultiMenu();
$options=array('40');
$menu_num = $gmm->theme_menu();
if ( !empty($menu_num) ) {
$block = $gmm->getblock( $options, 'multimenu0' . $menu_num );
$xoopsTpl->assign( 'multiMenuToTheme' , $block ) ; // Insert smarty for entire site theme
}
$flow = new multiMenuFlow($gmm);
if ($flow->nextLink){
// die($flow->nextLink);
$_SESSION['multiMenuFlow'] = array();
redirect_header($flow->nextLink,3,'Multimeu Flow next link. ');
// $this->mController->executeForward($flow->nextLink);
}
}
}
/*
* hook Flow
*/
class multimenuFlow {
var $moduleId = null;
var $nextLink = null;
var $flowLink = null;
var $pathMatch = false;
function __construct($gmm){
global $xoopsUser,$xoopsDB;
if ($xoopsUser){
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')? 'https': 'http';
$requestUrl = $protocol.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$refererUrl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL;
if( isset($_SESSION['multiMenuFlow']) && isset($_SESSION['multiMenuFlow']['nextId'] )){
if( $refererUrl != $_SESSION['multiMenuFlow']['requestUrl'] ){
$nextId = $_SESSION['multiMenuFlow']['nextId'];
$this->nextLink = $_SESSION['multiMenuFlow']['nextLink'];
$this->moveFlowPosition($nextId);
return;
}
}
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')? 'https': 'http';
$requestUrl = $protocol.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$options = array('40');
$block = $gmm->getblock( $options, 'multimenu99');
$sql = 'SELECT id FROM ' .$xoopsDB->prefix('multimenu_log') . ' WHERE uid=' . $xoopsUser->uid() . ';';
$ret = $xoopsDB->query($sql);
$id = NULL;
if ($ret) list($id) = $xoopsDB->fetchRow($ret);
if (!isset($block['contents'])) return NULL;
$link_option = NULL;
foreach($block['contents'] as $b){
if(!is_null($this->flowLink)){
$nextId = $b['id'];
$nextLink = $b['link'];
break;
}
if ($b['id'] == $id || $id==NULL){
$this->flowLink = $nextLink = $b['link']; // selected flow link
}
}
/*
* Back to Flow Top When same as top link
*/
if( $this->linkComp($refererUrl,$block['contents'][0]['link']) == true ){
$topId = $block['contents'][0]['id'];
$this->moveFlowPosition($topId);
}
/*
* Check and Move Flow
*/
$ret = $this->linkComp($refererUrl,$this->flowLink,$link_option);
// Redirect to new Flow menu
if ( $ret && (isset($_POST['submit']) || isset($_POST['contents_submit'])) ){
$_SESSION['multiMenuFlow']['nextId'] = $nextId;
$_SESSION['multiMenuFlow']['nextLink'] = $nextLink;
$_SESSION['multiMenuFlow']['requestUrl'] = $requestUrl;
}
}
}
private function getModuleId($refererUrl){
$req = parse_url($refererUrl);
$mydirname = basename( dirname( $req['path'] ));
$module_handler = xoops_gethandler( 'module' );
$module = $module_handler->getByDirname($mydirname);
if ($module) return $module->mid();
}
private function moveFlowPosition($id){
global $xoopsUser,$xoopsDB;
// Record to log
if (is_null($id)) return;
$sql = 'INSERT INTO ' .$xoopsDB->prefix('multimenu_log')
.' (uid,id) VALUES('.$xoopsUser->uid().','.$id . ')';
$ret = $xoopsDB->queryF($sql);
if(!$ret){
$sql = 'UPDATE ' .$xoopsDB->prefix('multimenu_log')
.' SET id=' . $id . ' WHERE uid='.$xoopsUser->uid().';';
$ret = $xoopsDB->queryF($sql);
}
}
private function linkComp($refererUrl,$flowLink,$option=''){
//echo '<hr>requestUrl: '.$refererUrl . '<br />'. 'flowLink: '. $flowLink .'<br />';
if (! $refererUrl) {
return false;
}
if (! $req = parse_url($refererUrl)) {
return false;
}
if (! $flo = parse_url($flowLink)) {
return false;
}
$parse = array('query'=>true);
if ( substr($req['path'], -1)=='/') $req['path'] .= 'index.php';
foreach($flo as $key => $val){
if ($key=='path' && substr($val, -1)=='/'){
$val .= 'index.php';
}
if (!isset($req[$key])){
if ($key!='query'){
$parse[$key] = false;
}
break;
}
//echo '<br />' . $key . ':' . $val . '<->' . $req[$key];
if (strcmp($val,$req[$key])==0){
$parse[$key] = true;
}else{
$parse[$key] = false;
}
if ($key=='query'){
$f_prm = explode('&',$val);
$r_prm = explode('&',$req[$key]);
$r_prm = array_merge($r_prm, explode('&',$option));
//echo '<br />req: '; var_dump($r_prm);
$parse[$key] = false;
foreach($f_prm as $k=>$v){
if(in_array($v,$r_prm)){
//echo '<br />v: '.$v;
$parse[$key] = true;
}
}
}
}
if ( isset($parse['path']) ){
$this->pathMatch = $parse['path'];
}
$ret = true;
if ($parse && in_array(false,$parse)){
$ret = false;
}
//if ($ret==true) echo 'Move Ok.<br />';else echo 'Move NO.<br />';
return $ret;
}
}
?>