@@ -24,28 +24,66 @@ public function indexAction()
24
24
{
25
25
throw new Zend_Exception ("This item doesn't exist or you don't have the permissions. " );
26
26
}
27
+
28
+ $ modulesConfig =Zend_Registry::get ('configsModules ' );
29
+ $ paraviewworkdir = $ modulesConfig ['visualize ' ]->paraviewworkdir ;
30
+ $ customtmp = $ modulesConfig ['visualize ' ]->customtmp ;
31
+ $ useparaview = $ modulesConfig ['visualize ' ]->useparaview ;
32
+ $ userwebgl = $ modulesConfig ['visualize ' ]->userwebgl ;
33
+ if (!isset ($ useparaview ) || !$ useparaview )
34
+ {
35
+ throw new Zend_Exception ('Please unable paraviewweb ' );
36
+ }
27
37
28
- if (!file_exists ( BASE_PATH . ' /tmp/visualize ' ))
38
+ if (!isset ( $ paraviewworkdir ) || empty ( $ paraviewworkdir ))
29
39
{
30
- mkdir (BASE_PATH .'/tmp/visualize ' );
40
+ throw new Zend_Exception ('Please set the paraview work directory ' );
41
+ }
42
+
43
+ if (isset ($ customtmp ) && !empty ($ customtmp ))
44
+ {
45
+ $ tmp_dir = $ customtmp ;
46
+ if (!file_exists ($ tmp_dir ) || !is_writable ($ tmp_dir ))
47
+ {
48
+ throw new Zend_Exception ('Unable to access temp dir ' );
49
+ }
50
+ }
51
+ else
52
+ {
53
+ if (!file_exists (BASE_PATH .'/tmp/visualize ' ))
54
+ {
55
+ mkdir (BASE_PATH .'/tmp/visualize ' );
56
+ }
57
+ $ tmp_dir = BASE_PATH .'/tmp/visualize ' ;
58
+ }
59
+
60
+ $ dir = opendir ($ tmp_dir );
61
+ while ($ entry = readdir ($ dir ))
62
+ {
63
+ if (is_dir ($ tmp_dir .'/ ' .$ entry ) && filemtime ($ tmp_dir .'/ ' .$ entry ) < strtotime ('-1 hours ' ) && !in_array ($ entry , array ('. ' ,'.. ' )))
64
+ {
65
+ if (strpos ($ entry , 'Paraview ' ) !== false )
66
+ {
67
+ $ this ->rrmdir ($ tmp_dir .'/ ' .$ entry );
68
+ }
69
+ }
31
70
}
32
-
33
71
do
34
72
{
35
73
$ tmpFolderName = 'ParaviewWeb_ ' .mt_rand (0 , 9999999 );
36
- $ path = BASE_PATH . ' /tmp/visualize / ' .$ tmpFolderName ;
74
+ $ path = $ tmp_dir . ' / ' .$ tmpFolderName ;
37
75
}
38
- while (!mkdir ($ path, ' 700 ' ));
76
+ while (!mkdir ($ path ));
39
77
40
78
$ revision = $ this ->Item ->getLastRevision ($ item );
41
79
$ bitstreams = $ revision ->getBitstreams ();
42
80
foreach ($ bitstreams as $ bitstream )
43
81
{
44
82
copy ($ bitstream ->getFullPath (), $ path .'/ ' .$ bitstream ->getName ());
45
- $ ext = substr (strrchr ($ bitstream ->getName (), '. ' ), 1 );
83
+ $ ext = strtolower ( substr (strrchr ($ bitstream ->getName (), '. ' ), 1 ) );
46
84
if ($ ext != 'pvsm ' )
47
85
{
48
- $ filePath = " /workspace/PW-work/midas / " .$ tmpFolderName .'/ ' .$ bitstream ->getName ();
86
+ $ filePath = $ paraviewworkdir . " / " .$ tmpFolderName .'/ ' .$ bitstream ->getName ();
49
87
$ mainBitstream = $ bitstream ;
50
88
}
51
89
}
@@ -54,12 +92,12 @@ public function indexAction()
54
92
55
93
foreach ($ bitstreams as $ bitstream )
56
94
{
57
- $ ext = substr (strrchr ($ bitstream ->getName (), '. ' ), 1 );
95
+ $ ext = strtolower ( substr (strrchr ($ bitstream ->getName (), '. ' ), 1 ) );
58
96
if ($ ext == 'pvsm ' )
59
97
{
60
98
$ file_contents = file_get_contents ($ path .'/ ' .$ bitstream ->getName ());
61
99
$ file_contents = preg_replace ('/\"([a-zA-Z0-9_.\/ \\\:]{1,1000}) ' . str_replace ('. ' , '\. ' , $ mainBitstream ->getName ())."/ " , '" ' .$ filePath , $ file_contents );
62
- $ filePath = " /workspace/PW-work/midas / " .$ tmpFolderName .'/ ' .$ bitstream ->getName ();
100
+ $ filePath = $ paraviewworkdir . " / " .$ tmpFolderName .'/ ' .$ bitstream ->getName ();
63
101
$ inF = fopen ($ path .'/ ' .$ bitstream ->getName (),"w " );
64
102
fwrite ($ inF , $ file_contents );
65
103
fclose ($ inF );
@@ -69,18 +107,44 @@ public function indexAction()
69
107
}
70
108
71
109
72
- if ($ item ->getSizebytes ()> 1 *1024 *1024 )
110
+ if (! $ userwebgl || $ item ->getSizebytes ()> 1 *1024 *1024 )
73
111
{
74
112
$ this ->view ->renderer = 'js ' ;
75
113
}
76
114
else
77
115
{
78
116
$ this ->view ->renderer = 'webgl ' ;
79
117
}
80
-
81
118
$ this ->view ->json ['visualize ' ]['url ' ] = $ filePath ;
82
119
$ this ->view ->json ['visualize ' ]['width ' ] = $ this ->_getParam ('width ' );
83
- $ this ->view ->json ['visualize ' ]['height ' ] = $ this ->_getParam ('height ' );
120
+ $ this ->view ->json ['visualize ' ]['height ' ] = $ this ->_getParam ('height ' );
121
+ $ this ->view ->usewebgl = $ userwebgl ;
84
122
}
123
+
124
+ /** recursively delete a folder*/
125
+ private function rrmdir ($ dir )
126
+ {
127
+ if (is_dir ($ dir ))
128
+ {
129
+ $ objects = scandir ($ dir );
130
+ }
131
+
132
+ foreach ($ objects as $ object )
133
+ {
134
+ if ($ object != ". " && $ object != ".. " )
135
+ {
136
+ if (filetype ($ dir ."/ " .$ object ) == "dir " )
137
+ {
138
+ $ this ->rrmdir ($ dir ."/ " .$ object );
139
+ }
140
+ else
141
+ {
142
+ unlink ($ dir ."/ " .$ object );
143
+ }
144
+ }
145
+ }
146
+ reset ($ objects );
147
+ rmdir ($ dir );
148
+ }
85
149
} // end class
86
150
?>
0 commit comments