@@ -52,7 +52,6 @@ public function register(Doku_Event_Handler $controller) {
5252 */
5353 public function convert (Doku_Event $ event , $ param ) {
5454 global $ ACT ;
55- global $ REV ;
5655 global $ ID ;
5756
5857 // our event?
@@ -70,51 +69,9 @@ public function convert(Doku_Event $event, $param) {
7069 // it's ours, no one else's
7170 $ event ->preventDefault ();
7271
73- // prepare cache
74- $ cachekey = join (', ' , $ this ->list )
75- . $ REV
76- . $ this ->getExportConfig ('template ' )
77- . $ this ->getExportConfig ('pagesize ' )
78- . $ this ->getExportConfig ('orientation ' )
79- . $ this ->getExportConfig ('doublesided ' )
80- . ($ this ->getExportConfig ('hasToC ' ) ? join ('- ' , $ this ->getExportConfig ('levels ' )) : '0 ' )
81- . $ title ;
82- $ cache = new cache ($ cachekey , '.dw2.pdf ' );
83-
84- $ dependencies = array ();
85- foreach ($ this ->list as $ pageid ) {
86- $ relations = p_get_metadata ($ pageid , 'relation ' );
87-
88- if (is_array ($ relations )) {
89- if (array_key_exists ('media ' , $ relations ) && is_array ($ relations ['media ' ])) {
90- foreach ($ relations ['media ' ] as $ mediaid => $ exists ) {
91- if ($ exists ) {
92- $ dependencies [] = mediaFN ($ mediaid );
93- }
94- }
95- }
96-
97- if (array_key_exists ('haspart ' , $ relations ) && is_array ($ relations ['haspart ' ])) {
98- foreach ($ relations ['haspart ' ] as $ part_pageid => $ exists ) {
99- if ($ exists ) {
100- $ dependencies [] = wikiFN ($ part_pageid );
101- }
102- }
103- }
104- }
105-
106- $ dependencies [] = metaFN ($ pageid ,'.meta ' );
107- }
108-
109- $ depends ['files ' ] = array_map ('wikiFN ' , $ this ->list );
110- $ depends ['files ' ][] = __FILE__ ;
111- $ depends ['files ' ][] = dirname (__FILE__ ) . '/renderer.php ' ;
112- $ depends ['files ' ][] = dirname (__FILE__ ) . '/mpdf/mpdf.php ' ;
113- $ depends ['files ' ] = array_merge (
114- $ depends ['files ' ],
115- $ dependencies ,
116- getConfigFiles ('main ' )
117- );
72+ // prepare cache and its dependencies
73+ $ depends = array ();
74+ $ cache = $ this ->prepareCache ($ title , $ depends );
11875
11976 // hard work only when no cache available
12077 if (!$ this ->getConf ('usecache ' ) || !$ cache ->useCache ($ depends )) {
@@ -215,6 +172,62 @@ protected function collectExportPages(Doku_Event $event) {
215172 return array ($ title , $ list );
216173 }
217174
175+ /**
176+ * Prepare cache
177+ *
178+ * @param string $title
179+ * @param array $depends (reference) array with dependencies
180+ * @return cache
181+ */
182+ protected function prepareCache ($ title , &$ depends ) {
183+ global $ REV ;
184+
185+ $ cachekey = join (', ' , $ this ->list )
186+ . $ REV
187+ . $ this ->getExportConfig ('template ' )
188+ . $ this ->getExportConfig ('pagesize ' )
189+ . $ this ->getExportConfig ('orientation ' )
190+ . $ this ->getExportConfig ('doublesided ' )
191+ . ($ this ->getExportConfig ('hasToC ' ) ? join ('- ' , $ this ->getExportConfig ('levels ' )) : '0 ' )
192+ . $ title ;
193+ $ cache = new cache ($ cachekey , '.dw2.pdf ' );
194+
195+ $ dependencies = array ();
196+ foreach ($ this ->list as $ pageid ) {
197+ $ relations = p_get_metadata ($ pageid , 'relation ' );
198+
199+ if (is_array ($ relations )) {
200+ if (array_key_exists ('media ' , $ relations ) && is_array ($ relations ['media ' ])) {
201+ foreach ($ relations ['media ' ] as $ mediaid => $ exists ) {
202+ if ($ exists ) {
203+ $ dependencies [] = mediaFN ($ mediaid );
204+ }
205+ }
206+ }
207+
208+ if (array_key_exists ('haspart ' , $ relations ) && is_array ($ relations ['haspart ' ])) {
209+ foreach ($ relations ['haspart ' ] as $ part_pageid => $ exists ) {
210+ if ($ exists ) {
211+ $ dependencies [] = wikiFN ($ part_pageid );
212+ }
213+ }
214+ }
215+ }
216+
217+ $ dependencies [] = metaFN ($ pageid , '.meta ' );
218+ }
219+
220+ $ depends ['files ' ] = array_map ('wikiFN ' , $ this ->list );
221+ $ depends ['files ' ][] = __FILE__ ;
222+ $ depends ['files ' ][] = dirname (__FILE__ ) . '/renderer.php ' ;
223+ $ depends ['files ' ][] = dirname (__FILE__ ) . '/mpdf/mpdf.php ' ;
224+ $ depends ['files ' ] = array_merge (
225+ $ depends ['files ' ],
226+ $ dependencies ,
227+ getConfigFiles ('main ' )
228+ );
229+ return $ cache ;
230+ }
218231
219232 /**
220233 * Set error notification and reload page again
0 commit comments