/[drupal]/contributions/modules/phpbbforum/phpbbforum.theme.inc
ViewVC logotype

Contents of /contributions/modules/phpbbforum/phpbbforum.theme.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download) (as text)
Mon Aug 31 21:08:03 2009 UTC (2 months, 3 weeks ago) by vb
Branch: MAIN
CVS Tags: DRUPAL-6--2-0-BETA6, DRUPAL-6--2-0-BETA7, DRUPAL-5--2-0-BETA6, HEAD
Changes since 1.15: +549 -550 lines
File MIME type: text/x-php
Bugs and new comments
1 <?php
2 // $Id: phpbbforum.theme.inc,v 1.15 2009/05/18 18:13:30 vb Exp $
3 /**
4 * Copyright 2008-2009 by Vadim G.B. (http://vgb.org.ru)
5 */
6
7 if (PHPBB_DRUPAL_MODULE_VERSION != 5) {
8 /**
9 * Implementation of hook_theme().
10 */
11 function phpbbforum_theme() {
12 return array(
13 'phpbbforum_whos_online' => array(
14 'arguments' => array('output' => NULL, 'options' => NULL),
15 ),
16 'phpbbforum_recent_posts' => array(
17 'arguments' => array('output' => NULL, 'options' => NULL),
18 ),
19 'phpbbforum_recent_topics' => array(
20 'arguments' => array('output' => NULL, 'options' => NULL),
21 ),
22 'phpbbforum_board_stats' => array(
23 'arguments' => array('output' => NULL, 'options' => NULL),
24 ),
25 'phpbbforum_pm' => array(
26 'arguments' => array('output' => NULL, 'options' => NULL),
27 ),
28 'phpbbforum_topposter' => array(
29 'arguments' => array('output' => NULL, 'options' => NULL),
30 ),
31 'phpbbforum_style' => array(
32 'arguments' => array('style' => NULL, 'phpbb_theme_path' => NULL, 'output' => NULL),
33 ),
34 );
35 }
36 }
37
38 function phpbbforum_whos_online() {
39 global $phpbb_config, $phpbb_user, $_phpbb_integration_mode;
40
41 $options = array(
42 'num_top' => (int)variable_get('phpbbforum_num_whos_online', PHPBB_NUM_WHOS_ONLINE),
43 'output_method' => 'array',
44 );
45 $output = phpbb_api_whos_online($options);
46 $output = theme('phpbbforum_whos_online', $output, $options);
47 if ($_phpbb_integration_mode != '0')
48 $output = _phpbbforum_replace_links($output);
49
50 return $output;
51 }
52
53 function phpbbforum_recent_posts() {
54 global $phpbb_config, $phpbb_user, $_phpbb_integration_mode;
55
56 if (variable_get('phpbbforum_recent_posts_br', 1))
57 $delimeter = PHPBB_RECENT_DELIMITER_BR;
58 else
59 $delimeter = PHPBB_RECENT_DELIMITER_SPACE;
60
61 $options = array(
62 'num_recent' => (int)variable_get('phpbbforum_num_recent_posts', PHPBB_NUM_RECENT_POSTS),
63 'search_id' => 'newposts',
64 'sort_days' => (int)variable_get('phpbbforum_num_recent_sort_days', 0),
65 'output_tag' => '<ul class="menu">',
66 'output_br' => $delimeter,
67 'display_mode' => variable_get('phpbbforum_recent_posts_display_mode', 0),
68 'display_topic_new_icon_pos' => variable_get('phpbbforum_recent_display_topic_new_icon_pos', 0),
69 'output_method' => 'array',
70 );
71 $output = phpbb_api_recent_posts($options);
72 $output = theme('phpbbforum_recent_posts', $output, $options);
73 if ($_phpbb_integration_mode != '0')
74 $output = _phpbbforum_replace_block_links($output);
75
76 return $output;
77 }
78
79 function phpbbforum_recent_topics() {
80 global $phpbb_config, $phpbb_user, $_phpbb_integration_mode;
81
82 if (variable_get('phpbbforum_recent_topics_br', 1))
83 $delimeter = PHPBB_RECENT_DELIMITER_BR;
84 else
85 $delimeter = PHPBB_RECENT_DELIMITER_SPACE;
86
87 $options = array(
88 'num_recent' => (int)variable_get('phpbbforum_num_recent_topics', PHPBB_NUM_RECENT_TOPICS),
89 'search_id' => 'active_topics',
90 'sort_days' => (int)variable_get('phpbbforum_num_recent_sort_days', 0),
91 'output_tag' => '<ul class="menu">',
92 'output_br' => $delimeter,
93 'display_mode' => variable_get('phpbbforum_recent_topics_display_mode', 0),
94 'display_topic_new_icon_pos' => variable_get('phpbbforum_recent_display_topic_new_icon_pos', 0),
95 'output_method' => 'array',
96 );
97 $output = phpbb_api_recent_topics($options);
98 $output = theme('phpbbforum_recent_topics', $output, $options);
99 if ($_phpbb_integration_mode != '0')
100 $output = _phpbbforum_replace_block_links($output);
101
102 return $output;
103 }
104
105 function phpbbforum_board_stats() {
106 global $phpbb_config, $phpbb_user, $_phpbb_integration_mode;
107
108 $options = array(
109 'output_method' => 'array',
110 );
111 $output = phpbb_api_board_stats($options);
112 $output = theme('phpbbforum_board_stats', $output, $options);
113 if ($_phpbb_integration_mode != '0')
114 $output = _phpbbforum_replace_block_links($output);
115
116 return $output;
117 }
118
119 function phpbbforum_pm() {
120 global $phpbb_config, $phpbb_user, $_phpbb_integration_mode;
121
122 if (variable_get('phpbbforum_pm_br', 1))
123 $delimeter = PHPBB_RECENT_DELIMITER_BR;
124 else
125 $delimeter = PHPBB_RECENT_DELIMITER_SPACE;
126 $options = array(
127 'output_br' => $delimeter,
128 'display_mode' => variable_get('phpbbforum_pm_display_mode', 0),
129 'output_method' => 'array',
130 );
131 $output = phpbb_api_pm($options);
132 $output = theme('phpbbforum_pm', $output, $options);
133 if ($_phpbb_integration_mode != '0')
134 $output = _phpbbforum_replace_block_links($output);
135
136 return $output;
137 }
138
139 function phpbbforum_topposter() {
140 global $phpbb_config, $phpbb_user, $_phpbb_integration_mode;
141
142 $options = array(
143 'num_top' => (int)variable_get('phpbbforum_num_top_posters', PHPBB_NUM_TOP_POSTERS),
144 'output_method' => 'array',
145 );
146 $output = phpbb_api_topposter($options);
147 $output = theme('phpbbforum_topposter', $output, $options);
148 if ($_phpbb_integration_mode != '0')
149 $output = _phpbbforum_replace_block_links($output);
150
151 return $output;
152 }
153
154
155 function theme_phpbbforum_whos_online($output, $options) {
156 return theme_phpbb_api_whos_online($output, $options);
157 }
158
159 function theme_phpbbforum_recent_posts($posts, $options) {
160 return theme_phpbb_api_recent_posts($posts, $options);
161 }
162
163 function theme_phpbbforum_recent_topics($posts, $options) {
164 return theme_phpbb_api_recent_topics($posts, $options);
165 }
166
167 function theme_phpbbforum_board_stats($output, $options) {
168 return theme_phpbb_api_board_stats($output, $options);
169 }
170
171 function theme_phpbbforum_pm($output, $options) {
172 return theme_phpbb_api_pm($output, $options);
173 }
174
175 function theme_phpbbforum_topposter($posters, $options) {
176 return theme_phpbb_api_topposter($posters, $options);
177 }
178
179 function theme_phpbbforum_style($style, $phpbb_theme_path, $output) {
180 if (variable_get("phpbbforum_page_frame", 0) == '0')
181 return '';
182 return phpbbforum_style($style, $phpbb_theme_path, $output);
183 }
184
185 if (variable_get("phpbbforum_page_frame", 0) == '1' || variable_get("phpbbforum_page_frame", 0) == '2') {
186
187 ////////////////////////////////////////////////////////////////////////////////
188
189 function phpbbforum_set_style($style, $phpbb_theme_path) {
190
191 global $phpbb_config, $phpbb_user, $phpbb_root_path;
192
193 $style = str_replace('-', '_', $style);
194
195 $fn = 'phpbbforum_set_style_'. $style;
196 if (function_exists($fn)) {
197 $fn($phpbb_theme_path);
198 }
199 else {
200 $styleclass = (stripos($style, 'prosilver') || substr($style, 0, 3) == 'pro');
201 if ($styleclass !== false) {
202 phpbbforum_set_style_prosilver($phpbb_theme_path);
203 }
204 else {
205 phpbbforum_set_style_subsilver2($phpbb_theme_path);
206 }
207 }
208 }
209
210 function phpbbforum_style($style, $phpbb_theme_path, $output) {
211
212 global $phpbb_config, $phpbb_user, $phpbb_root_path, $_phpbb_result;
213
214 drupal_set_title($_phpbb_result['page_title']);
215
216 if ($_phpbb_result['meta_refresh'] > 0 ) {
217 $url = $_phpbb_result['destination'];
218 $time = $_phpbb_result['meta_refresh'];
219 drupal_set_html_head('<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '" />');
220 }
221
222 $type = 'theme';
223 drupal_add_css(drupal_get_path('module', 'phpbbforum') .'/css/phpbbforum.css', $type);
224
225 $style = str_replace('-', '_', $style);
226
227 $fn = 'phpbbforum_style_'. $style;
228 if (function_exists($fn)) {
229 $output = $fn($phpbb_theme_path, $output);
230 }
231 else {
232 $styleclass = (stripos($style, 'prosilver') || substr($style, 0, 3) == 'pro');
233 if ($styleclass !== false) {
234 $output = phpbbforum_style_prosilver($phpbb_theme_path, $output);
235 }
236 else {
237 $output = phpbbforum_style_subsilver2($phpbb_theme_path, $output);
238 }
239 }
240
241 drupal_add_js(drupal_get_path('module', 'phpbbforum') .'/js/phpbbforum.js', 'module');
242
243 $phpbb_url = $phpbb_config['forum_url'] .'/';
244
245 $output = str_replace($phpbb_root_path, $phpbb_url, $output);
246 $output = _phpbbforum_replace_links($output);
247
248 $output = '<div id="phpbbforum-page">'. $output .'</div><!-- /phpbbforum-page -->';
249
250 return $output;
251 }
252
253
254
255 /*
256 function _phpbbforum_set_head_script1($endpos, $output) {
257
258 $tag = '<!-- phpbbforum-page-head -->';
259 $scripttag = '<script type="text/javascript">';
260
261 $startpos = strpos($output, $tag, $endpos);
262 if ($startpos !== false) {
263 $startpos = strpos($output, $scripttag, $startpos + strlen($tag));
264 }
265 else {
266 $startpos = strpos($output, $scripttag);
267 }
268 if ($startpos !== false) {
269 $startpos = strpos($output, '// <![CDATA[', $startpos + strlen($scripttag));
270 if ($startpos !== false) {
271 $startpos += 12;
272 $endpos = strpos($output, '// ]]>', $startpos);
273 if ($endpos) {
274 $script = substr($output, $startpos, ($endpos - $startpos));
275 if ($script != '') {
276 drupal_add_js($script, 'inline');
277 }
278 }
279 }
280 }
281
282 return $endpos;
283 }
284 */
285
286 function _phpbbforum_get_html_body($endpos, $output) {
287 $startpos = strpos($output, '<body', $endpos);
288 if ($startpos) {
289 $startpos = strpos($output, '>', $startpos) + 1;
290 $endpos = strpos($output, '</body>', $startpos);
291 if ($endpos)
292 $output = substr($output, $startpos, ($endpos - $startpos));
293 }
294 return $output;
295 }
296
297 function _phpbbforum_get_html_tag(&$endpos, $output, $tag, $endtag = '</div>', $mode = 0) {
298 $startpos = strpos($output, $tag, $endpos);
299 if ($startpos !== false) {
300 $endpos2 = strpos($output, $endtag, $startpos);
301 if ($endpos2 !== false) {
302 $len = $endpos2 - $startpos;
303 if ($mode == 0) {
304 $len += strlen($endtag);
305 $endpos2 += strlen($endtag);
306 } elseif ($mode == 1) {
307 $startpos += strlen($tag);
308 }
309 $output = substr($output, $startpos, $len);
310 $endpos = $endpos2;
311 }
312 }
313 return $output;
314 }
315
316 function _phpbbforum_set_theme_css($phpbb_theme_path, $phpbb_theme) {
317
318 global $language, $theme;
319
320 $type = 'theme';
321
322 $module_css = '/'. $theme .'-phpbbforum-'. $phpbb_theme .'.css';
323 $theme_css_file = drupal_get_path('theme', $theme) . $module_css;
324 if (!file_exists($theme_css_file)) {
325 $theme_css_file = drupal_get_path('module', 'phpbbforum') .'/css'. $module_css;
326 if (!file_exists($theme_css_file)) {
327 $module_css = '/phpbbforum-'. $phpbb_theme .'.css';
328 $theme_css_file = drupal_get_path('theme', $theme) .'/css'. $module_css;
329 if (!file_exists($theme_css_file)) {
330 $theme_css_file = drupal_get_path('module', 'phpbbforum') .'/css'. $module_css;
331 }
332 }
333 }
334 drupal_add_css($theme_css_file, $type);
335 }
336
337 ////////////////////////////////////////////////////////////////////////////////
338
339 /*
340 * prosilver
341 */
342
343 function _phpbbforum_set_head_script_prosilver($endpos, $output) {
344
345 global $_drupal_base_path, $base_path;
346
347 $scripttag = '<script type="text/javascript">';
348
349 $startpos = strpos($output, $scripttag, $endpos);
350 if ($startpos !== false) {
351 $endpos = strpos($output, '<link', $startpos + strlen($scripttag));
352 if ($endpos) {
353 $script = substr($output, $startpos, ($endpos - $startpos));
354 if ($script != '') {
355 $path = str_replace('\\', '/', $_drupal_base_path) .'/';
356 $str = array($path, strtolower($path));
357 $script = str_replace($str, $base_path, $script);
358 $script = _phpbbforum_replace_forum_url($script);
359 drupal_set_html_head($script);
360 }
361 }
362 }
363
364 return $endpos;
365 }
366
367 function _phpbbforum_set_head_links_prosilver($endpos, $output) {
368
369 global $_drupal_base_path, $base_path;
370
371 $linkstag = '<link href="';
372
373 $startpos = strpos($output, $linkstag, $endpos);
374 if ($startpos !== false) {
375 $endpos = strpos($output, 'printonly', $startpos + 1);
376 if ($endpos !== false) {
377 $startpos = strpos($output, $linkstag, $endpos);
378 if ($startpos !== false) {
379 $endpos = strpos($output, '</head>', $startpos + 1);
380 if ($endpos) {
381 $links = substr($output, $startpos, ($endpos - $startpos));
382 if ($links != '') {
383 $path = str_replace('\\', '/', $_drupal_base_path) .'/';
384 $str = array($path, strtolower($path));
385 $links = str_replace($str, $base_path, $links);
386 drupal_set_html_head($links);
387 }
388 }
389 }
390 }
391 }
392
393 return $endpos;
394 }
395
396 function phpbbforum_set_style_prosilver($phpbb_theme_path) {
397 _phpbbforum_set_theme_css($phpbb_theme_path, 'prosilver');
398 }
399
400 function phpbbforum_style_prosilver($phpbb_theme_path, $output) {
401
402 phpbbforum_set_style_prosilver($phpbb_theme_path);
403
404 $endpos = _phpbbforum_set_head_script_prosilver(0, $output);
405 $endpos = _phpbbforum_set_head_links_prosilver($endpos, $output);
406
407 $output = _phpbbforum_get_html_body($endpos, $output);
408
409 return $output;
410 }
411
412 /*
413 * prosilver_embed
414 */
415
416 function phpbbforum_set_style_prosilver_embed($phpbb_theme_path) {
417 phpbbforum_set_style_prosilver($phpbb_theme_path);
418 }
419
420 function phpbbforum_style_prosilver_embed($phpbb_theme_path, $output) {
421
422 phpbbforum_set_style_prosilver_embed($phpbb_theme_path);
423
424 $endpos = _phpbbforum_set_head_script_prosilver(0, $output);
425 $endpos = _phpbbforum_set_head_links_prosilver($endpos, $output);
426
427 $output = _phpbbforum_get_html_body($endpos, $output);
428
429 $endpos = 0;
430 $search_box = _phpbbforum_get_html_tag($endpos, $output, '<div id="search-box">');
431 $search_box = _phpbbforum_replace_forum_url($search_box);
432
433 //global $search;
434 //$search['search_theme_form'] = $search_box;
435
436 /*
437 $startpos = strpos($output, '<div id="page-header"');
438 if ($startpos !== false) {
439 $endpos = strpos($output, '<a name="start_here"></a>', $startpos + 1) + 6;
440 if ($endpos !== false) {
441 $outputlogo = substr($output, $startpos, ($endpos - 7 - $startpos));
442 $output = str_replace($outputlogo, '', $output);
443 }
444 }
445 */
446
447 return $output;
448 }
449
450 ////////////////////////////////////////////////////////////////////////////////
451
452 /*
453 * subsilver2
454 */
455
456 function _phpbbforum_set_head_links_subsilver2($endpos, $output) {
457
458 global $_drupal_base_path;
459
460 $linkstag = '<link';
461
462 $startpos = strpos($output, $linkstag, $endpos);
463 if ($startpos !== false) {
464 $endpos = strpos($output, '/>', $startpos + 1);
465 if ($endpos) {
466 $links = substr($output, $startpos, ($endpos - $startpos) + 2);
467 if ($links != '') {
468 $path = str_replace('\\', '/', $_drupal_base_path);
469 $str = array($path, strtolower($path));
470 $links = str_replace($str, '', $links);
471 drupal_set_html_head($links);
472 }
473 }
474 }
475
476 return $endpos;
477 }
478
479 function _phpbbforum_set_head_script_subsilver2($endpos, $output) {
480
481 global $_drupal_base_path;
482
483 $scripttag = '<script type="text/javascript">';
484
485 $startpos = strpos($output, $scripttag, $endpos);
486 if ($startpos !== false) {
487 $endpos = strpos($output, '</head>', $startpos + strlen($scripttag));
488 if ($endpos) {
489 $script = substr($output, $startpos, ($endpos - $startpos));
490 if ($script != '') {
491 $script = _phpbbforum_replace_forum_url($script);
492 drupal_set_html_head($script);
493 }
494 }
495 }
496
497 return $endpos;
498 }
499
500 function phpbbforum_set_style_subsilver2($phpbb_theme_path) {
501
502 _phpbbforum_set_theme_css($phpbb_theme_path, 'subsilver2');
503
504 $theme_js = $phpbb_theme_path .'/template/editor.js';
505 drupal_add_js($theme_js, 'module');
506 }
507
508 function phpbbforum_style_subsilver2($phpbb_theme_path, $output) {
509
510 phpbbforum_set_style_subsilver2($phpbb_theme_path);
511
512 $endpos = _phpbbforum_set_head_links_subsilver2(0, $output);
513 $endpos = _phpbbforum_set_head_script_subsilver2($endpos, $output);
514
515 $output = _phpbbforum_get_html_body($endpos, $output);
516
517 return $output;
518 }
519
520 /*
521 * subsilver2_embed
522 */
523 function phpbbforum_set_style_subsilver2_embed($phpbb_theme_path) {
524 phpbbforum_set_style_subsilver2($phpbb_theme_path);
525 }
526
527 function phpbbforum_style_subsilver2_embed($phpbb_theme_path, $output) {
528
529 phpbbforum_set_style_subsilver2_embed($phpbb_theme_path);
530
531 $endpos = _phpbbforum_set_head_links_subsilver2(0, $output);
532 $endpos = _phpbbforum_set_head_script_subsilver2($endpos, $output);
533
534 $output = _phpbbforum_get_html_body($endpos, $output);
535
536 /*
537 $startpos = strpos($output, '<div id="logodesc">');
538 if ($startpos !== false) {
539 $endpos = strpos($output, '</div>', $startpos + 1) + 6;
540 if ($endpos !== false) {
541 $outputlogo = substr($output, $startpos, ($endpos - $startpos));
542 $output = str_replace($outputlogo, '', $output);
543 }
544 }
545 */
546
547 return $output;
548 }
549
550 } // if (variable_get("phpbbforum_page_frame", 0) == '1' || variable_get("phpbbforum_page_frame", 0) == '2') {

  ViewVC Help
Powered by ViewVC 1.1.2