Browse the code
| Revision log Information on the revision | |
|---|---|
| Revision: | 511 (differences) |
| Author: | xbright |
| Log message: |
* Enhanced roadmap |
| Change revision: | |
0
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
<?php // This file is a part of CodingTeam. Take a look at <http://codingteam.org>. // Copyright © 2007-2012 Erwan Briand <erwan@codingteam.net> // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, version 3 only. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public // License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. /** * @file * This file contains the Template class * * Parse request of the user. * This can output XHTML, RSS, ATOM, SVG or XML/OpenForge. */ /** * Template class */ class Template { private $tpl, $page, $ct_session, $ct_db, $langlist, $lang, $error, $start_time; function __construct ($tpl, $page, $ct_session, $ct_db, $langlist, $lang, $error, $start_time) { $this->tpl = $tpl; $this->ct_session = $ct_session; $this->ct_db = $ct_db; $this->langlist = $langlist; $this->lang = $lang; $this->error = $error; $this->start_time = $start_time; // Remove empty data $page = explode('/', $page); foreach ($page as $key => $value) if (!empty($value) || $value == 0) $this->page[$key] = $value; /* Popularity contest. * Each projects have a popularity score and this score is resetted * each months. */ $cfg = getClass('config', $this->ct_db); $timestamp = $cfg->get('projects', 'popularity-timestamp'); if (!$timestamp || ( $timestamp + (86400 * 30) ) < time()) { // Reset popularity for each projects $this->ct_db->update('projects', array('popularity' => 0), FALSE); // Reset contest $cfg->update('projects', 'popularity-timestamp', time()); $cfg->update('projects', 'overall-popularity', 0); } // Cache maximum $this->cache_max_files = (int)$cfg->get('global', 'cache-max-files'); // Slogan $this->slogan = $cfg->get('global', 'slogan'); // Prepare switch ($this->page[1]) { case 'api': $this->parseAPI(); break; case 'atom': $this->parseAtom(); break; case 'rss': $this->parseRSS(); break; case 'svg': $this->parseSVG(); break; default: $this->parseXHTML(); } } /** * Parse API * * Print the XML output */ function parseAPI () { // Find the module that can generate the request if ($this->page[2] == 'user') $mod = CT_BASEDIR.'/inc/modules/users/views/show.php'; elseif ($this->page[2] == 'project') $mod = CT_BASEDIR.'/inc/modules/project/views/default.php'; elseif ($this->page[2] == 'search') $mod = CT_BASEDIR.'/inc/modules/search/views/default.php'; else exit('CodingTeam OpenForge API'); // Open the module view in the CodingTeam way if (is_file($mod)) { require($mod); $view_api = new View($this->ct_session, $this->ct_db, $this->page, $this->error, $this->langlist, $this->lang); $view_api->showAPI(); } else exit('CodingTeam OpenForge API'); } /** * Parse Atom * * Print the Atom output and save it in the cache for 7 days */ function parseAtom () { // Converting page tags $j = 1; for ($i=1; $i<=count($this->page); $i++) if (isset($this->page[$i]) && $this->page[$i] != 'atom') { $newpage[$j] = $this->page[$i]; $j ++; } $this->page = $newpage; // Cache Atom feed for 7 days max. $cachenamefile = CT_BASEDIR.'/public/cache/atom/'. mb_substr($this->lang, 0, 2).'-'. str_replace('/', '-', getURLbyTags($this->page)); if ( (file_exists($cachenamefile) && filemtime($cachenamefile) < time() - ( 3600 * 24 * 7 )) || !file_exists($cachenamefile) ) { // Find the requested module view if ($this->page[1] == 'project') if (empty($this->page[3])) $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/default.php'; else $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/'.$this->page[3].'.php'; elseif ($this->page[1] == 'admin') $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); else if (empty($this->page[2])) $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/default.php'; else $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/'.$this->page[2].'.php'; // Load the module if (is_file($mod)) { require($mod); $view_atom = new View($this->ct_session, $this->ct_db, $this->page, $this->error, $this->langlist, $this->lang); $atom_array = $view_atom->showFeed(); if (!is_array($atom_array)) $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); } else $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); // Create the Atom document Header("Content-Type: application/atom+xml; charset=utf-8"); $xml = new DOMDocument('1.0', 'utf-8'); $atom = $xml->createElement('feed'); $atom->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); $atom->setAttribute('xml:lang', mb_substr($this->lang, 0, 2)); $xml->appendChild($atom); $atom->appendChild($xml->createElement('id', CT_BASEURL.'atom/'. urlencode(getURLByTags($this->page)))); $atom->appendChild($xml->createElement('title', $atom_array['title'])); $atom->appendChild($xml->createElement('subtitle', $atom_array['description'])); $atom->appendChild($xml->createElement('updated', convertDate(time(), 'timestamp', 'rfc.3339'))); $link = $xml->createElement('link'); $link->setAttribute('rel', 'self'); $link->setAttribute('href', CT_BASEURL.'atom/'. getURLByTags($this->page)); $link->setAttribute('type', 'application/atom+xml'); $atom->appendChild($link); // Add latest items to the feed if (isset($atom_array['threads']) && is_array($atom_array['threads'])) { foreach ($atom_array['threads'] as $thread) { $item = $xml->createElement('entry'); $item->appendChild($xml->createElement('title', $thread['title'])); $time = convertDate($thread['pubDate'], 'datetime', 'timestamp'); $tim = convertDate($time, 'timestamp', 'rfc.3339'); $item->appendChild($xml->createElement('updated', $tim)); $item->appendChild($xml->createElement('id', $thread['guid'])); $link = $xml->createElement('link'); $link->setAttribute('href', $thread['link']); $item->appendChild($link); $author = $xml->createElement('author'); $author->appendChild($xml->createElement('name', $thread['dc:creator'])); $author->appendChild($xml->createElement('uri', CT_BASEURL.'users/show/'.$thread['dc:creator'])); $item->appendChild($author); $link = $xml->createElement('content', $thread['description']); $link->setAttribute('type', 'html'); $item->appendChild($link); $atom->appendChild($item); } } // Prepare the output $xml->formatOutput = true; $tpl_show = $xml->saveXML(); // Maximum files in cache $cachedir_ = CT_BASEDIR.'/public/cache/atom/'; $cachedir = opendir($cachedir_); $counter = 0; $cache_files = array(); // Count files in cache and create array while($f = readdir($cachedir)) if (is_file($cachedir_.$f)) { $cache_files[filemtime($cachedir_.$f)] = $cachedir_.$f; $counter ++; } closedir($cachedir); ksort($cache_files); // If we need to delete the oldest file before save our new one if ((count($cache_files) - 1) > ($this->cache_max_files / 2)) if (file_exists(reset($cache_files))) unlink(reset($cache_files)); if (mb_substr(getURLbyTags($this->page), 0, 17) != 'dashboard/default') { // Write in the cache $filec = fopen($cachenamefile, 'w'); fwrite($filec, $tpl_show); fclose($filec); } } else $tpl_show = file_get_contents($cachenamefile); // Show the result echo $tpl_show; } /** * Parse RSS * * Print the RSS output and save it in the cache for 7 days */ function parseRSS () { // Converting page tags $j = 1; for ($i=1; $i<=count($this->page); $i++) if (isset($this->page[$i]) && $this->page[$i] != 'rss') { $newpage[$j] = $this->page[$i]; $j ++; } $this->page = $newpage; // Cache RSS feed for 7 days max. $cachenamefile = CT_BASEDIR.'/public/cache/rss/'. mb_substr($this->lang, 0, 2).'-'. str_replace('/', '-', getURLbyTags($this->page)); if ( (file_exists($cachenamefile) && filemtime($cachenamefile) < time() - ( 3600 * 24 * 7 )) || !file_exists($cachenamefile)) { // Find the requested module view if ($this->page[1] == 'project') if (empty($this->page[3])) $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/default.php'; else $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/'.$this->page[3].'.php'; elseif ($this->page[1] == 'admin') $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); else if (empty($this->page[2])) $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/default.php'; else $mod = CT_BASEDIR.'/inc/modules/'.$this->page[1]. '/views/'.$this->page[2].'.php'; // Load the module if (is_file($mod)) { require($mod); $view_rss = new View($this->ct_session, $this->ct_db, $this->page, $this->error, $this->langlist, $this->lang); $rss_array = $view_rss->showFeed(); if (!is_array($rss_array)) $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); } else $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); // Create the RSS document Header("Content-Type: application/rss+xml; charset=utf-8"); $xml = new DOMDocument('1.0', 'utf-8'); $rss = $xml->createElement('rss'); $rss->setAttribute('version', '2.0'); $rss->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $xml->appendChild($rss); $channel = $xml->createElement('channel'); $rss->appendChild($channel); // Add informations on the feed $channel->appendChild($xml->createElement('title', $rss_array['title'])); $channel->appendChild($xml->createElement('link', $rss_array['link'])); $channel->appendChild($xml->createElement('description', $rss_array['description'])); $channel->appendChild($xml->createElement('language', mb_substr($this->lang, 0, 2))); // Add latest items to the feed if (isset($rss_array['threads']) && is_array($rss_array['threads'])) { foreach ($rss_array['threads'] as $thread) { $item = $xml->createElement('item'); $item->appendChild($xml->createElement('title', $thread['title'])); $item->appendChild($xml->createElement('pubDate', convertDate($thread['pubDate'], 'datetime', 'rfc'))); $item->appendChild($xml->createElement('guid', $thread['guid'])); $item->appendChild($xml->createElement('link', $thread['link'])); $item->appendChild($xml->createElement('dc:creator', $thread['dc:creator'])); $item->appendChild($xml->createElement('description', $thread['description'])); $channel->appendChild($item); } } // Prepare the output $xml->formatOutput = true; $tpl_show = $xml->saveXML(); // Maximum files in cache $cachedir_ = CT_BASEDIR.'/public/cache/rss/'; $cachedir = opendir($cachedir_); $counter = 0; $cache_files = array(); // Count files in cache and create array while($f = readdir($cachedir)) if (is_file($cachedir_.$f)) { $cache_files[filemtime($cachedir_.$f)] = $cachedir_.$f; $counter ++; } closedir($cachedir); ksort($cache_files); // If we need to delete the oldest file before save our new one if ((count($cache_files) - 1) > ($this->cache_max_files / 2)) if (file_exists(reset($cache_files))) unlink(reset($cache_files)); if (mb_substr(getURLbyTags($this->page), 0, 17) != 'dashboard/default') { // Write in the cache $filec = fopen($cachenamefile, 'w'); fwrite($filec, $tpl_show); fclose($filec); } } else $tpl_show = file_get_contents($cachenamefile); // Show the result echo $tpl_show; } /** * Parse SVG * * Print the SVG output. */ function parseSVG () { require(CT_BASEDIR.'/inc/classes/svg.php'); new SVG($this->ct_db, $this->page); } /** * Parse XHTML * * Print the XHTML output and save it in the cache for 7 days if user is * not logged. */ function parseXHTML () { // Change the path to the .tpl file $wtpl = CT_BASEDIR.'/inc/templates/'.CT_TEMPLATE_THEME.'/main.tpl'; if (file_exists($wtpl)) $this->tpl = $wtpl; // Test if URL contains _GET datas and delete them from the page array $_page_ = array(); $back = $this->page; foreach ($this->page as $arg) { if (mb_substr($arg, 0, 1) != '?') array_push($_page_, $arg); } $this->page = $_page_; // If a > 0 the page cannot be stored in the cache $a = 0; $nocache_keywords = array('register', 'logout', 'password', 'delete', 'admin', 'new', 'add', 'edit', 'answer', 'search', 'join', 'vote'); foreach ($nocache_keywords as $key) if (in_array($key, $this->page)) $a ++; if (in_array('bugs', $this->page) && in_array('show', $this->page)) $a ++; if (in_array('project', $this->page) && in_array('timeline', $this->page)) $a ++; // Also, no cache if an user try to login if ((isset($_POST['login_nickname']) && isset($_POST['login_password'])) OR isset($_POST['login_jabberid'])) $a ++; // If cache score equals zero and the user is not logged if (!$this->ct_session->isLogged($this->ct_db) && $a == 0) { // Set default expire time to one week (3600 * 24 * 7) $time = 604800; // Set the name of the file stored in cache $file = CT_BASEDIR.'/public/cache/xhtml/'. mb_substr($this->lang, 0, 2).str_replace('/', '-', getURLbyTags($back)); // If the page is already stored in the cache if (is_file($file)) { // Get meta information $cachefile = fopen($file, 'r'); $firstline = htmlspecialchars(fgets($cachefile, 1024)); // Set new expire time $info = explode('=', $firstline); if ($info[0] == 'expire') $time = $info[1]; fclose($cachefile); } // Rewrite the page in cache if expired or not exists if ( ( is_file($file) && filemtime($file) < ( time() - $time ) ) || !is_file($file) ) { $view = $this->loadView(); // Write meta information if expired time is not default if ($view['expire'] != $time) $additional = "expire=".$view['expire']."\n"; else $additional = ''; // Maximum files in cache $cachedir_ = CT_BASEDIR.'/public/cache/xhtml/'; $cachedir = opendir($cachedir_); $counter = 0; $cache_files = array(); // Count files in cache and create array while($f = readdir($cachedir)) if (is_file($cachedir_.$f)) { $cache_files[filemtime($cachedir_.$f)] = $cachedir_.$f; $counter ++; } closedir($cachedir); ksort($cache_files); // If we need to delete the oldest file before save our new // one. if ((count($cache_files) - 1) > $this->cache_max_files) if (file_exists(reset($cache_files))) unlink(reset($cache_files)); // Save in cache file_put_contents($file, $additional.$view['content']); $content = $view['content']; } // Just include the cache version else { $cachefile = file($file); $content = ''; // Check if the first line contains meta information $satanized = htmlspecialchars($cachefile[0]); if (mb_substr($satanized, 0, 7) == 'expire=') $start = 1; else $start = 0; for ($i=$start; $i<count($cachefile); $i++) $content .= $cachefile[$i]; } } else { $view = $this->loadView(); $content = $view['content']; } // Show the page echo str_replace('http://codingteam.net/', CT_BASEURL, $content); } /** * Load view * * Load view from module or plugin and return it in a view for parseXHTML. * @return * An array that contains XHTML string and expire time. */ function loadView() { // Set default expire time to one week (3600 * 24 * 7) $time_expire = 604800; // Find all "head modules" $headmodules = array(); $head = array(); $dir = CT_BASEDIR.'/inc/modules/'; $headmodulesdir = opendir($dir); while ($mod = readdir($headmodulesdir)) if (substr($mod, 0, 5) == 'head_') array_push($headmodules, $mod); // Load all head modules for($i=0; $i<count($headmodules); $i++) { require(CT_BASEDIR.'/inc/modules/'.$headmodules[$i].'/'. $headmodules[$i].'.php'); $head[$headmodules[$i]] = new $headmodules[$i]($this->ct_session, $this->ct_db, $this->page); $head[$headmodules[$i]]->treatForms(); } // Load asked module $xmlfile = CT_BASEDIR.'/inc/modules/'.$this->page[1].'/infos.xml'; if (is_file($xmlfile)) { // Start SimpleXML for parsing module informations $modxml = simplexml_load_file($xmlfile); $is_active = $modxml['active']; // If module is active if ($is_active == 'TRUE' && isset($modxml->views)) { // Get position of module and view in the URL $behavior_module = (int)($modxml->behavior['module-position']); $behavior_view = (int)($modxml->behavior['view-position']); // Set the module if (!isset($this->page[$behavior_module])) $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); else $module = $this->page[$behavior_module]; // Set the view if (!isset($this->page[$behavior_view])) $wished_view = 'default'; else if (!empty($this->page[$behavior_view])) $wished_view = $this->page[$behavior_view]; else { Header('Location: '.CT_BASEURL.$this->page[1]); exit(); } // Fetch all views foreach ($modxml->views->view as $view) { // If this the requested view if ($view['name'] == $wished_view) { $moduleview = 'views/'.$wished_view; // Exit if view is disabled $is_active = $view['active']; if ($is_active == 'FALSE') $this->error->displayError(i18n('This feature has'. ' been disabled by an administrator.'), 0); // Use another expire time if set if (!empty($view['expire'])) $time_expire = $view['expire']; } } } else $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); $is_this_admin = FALSE; } // If this is the admin module elseif ($this->page[1] == 'admin') { if (!isset($this->page[2])) { $module = 'admin'; $moduleview = 'views/default'; } else { $module = $this->page[2]; $moduleview = '_admin/'.$this->page[3]; } $is_this_admin = TRUE; } else $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); if (!isset($moduleview)) $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); // Load the wished view $view = CT_BASEDIR.'/inc/modules/'.$module.'/'.$moduleview.'.php'; if (is_file($view)) { require($view); $view_loaded = new View($this->ct_session, $this->ct_db, $this->page, $this->error, $this->langlist, $this->lang); // Do treatment for POST datas $view_loaded->treatForms(); } else $this->error->displayError(i18n('404 Document not found.'), 0, '404 Not Found'); // Get the content of the page $constructed_view = $view_loaded->constructView(); // Include template file $tpl_base = CT_BASEDIR.'/inc/modules/'.$module.'/templates/'; $tpl_file = $tpl_base.$constructed_view['__tpl__']; // Fills template ob_start(); array_shift($constructed_view); extract($constructed_view); include($tpl_file); $page_content = ob_get_contents(); ob_end_clean(); /* Ok. Now, we have generated our view based on the template and the * view class related to the request. * The next work is to integrate this content in the layout template. * Once we do that, our work will be ended. */ // Import the .tpl file $this->tpl_file = file_get_contents($this->tpl); $temp['tpl:lang'] = mb_substr($this->lang, 0, 2); $temp['tpl:cssdir'] = 'inc/templates/'.CT_TEMPLATE_THEME.'/'; $temp['tpl:images'] = 'public/images/'; $temp['tpl:logosimages'] = 'public/images/logos/'; // Generate the menu $tabs = array(); $modlist = array(); $modulesdir = opendir(CT_BASEDIR.'/inc/modules/'); while ($module_ = readdir($modulesdir)) { $xmlfile = CT_BASEDIR.'/inc/modules/'.$module_.'/infos.xml'; if (is_file($xmlfile)) { $modxml = simplexml_load_file($xmlfile); $is_active = $modxml['active']; if ($is_active == 'TRUE') { require_once(CT_BASEDIR.'/inc/modules/'. $module_.'/menu.php'); $classname = ucfirst($module_).'Menu'; $modmenu = new $classname($this->ct_db, $this->lang, $this->ct_session, $this->page, $modxml->views->view); $mmenu = $modmenu->getNotepadMenu(); if (is_array($mmenu) && $mmenu['force_login'] && !$this->ct_session->isLogged()) continue; if ($module_ == $module) $menu = $modmenu; if (is_array($mmenu)) { array_push($tabs, $mmenu); array_push($modlist, $module_); } } } } // Sort tabs $tabs_ = array(); foreach ($tabs as $tab_) { if (isset($tab_['position'])) $tabs_[$tab_['position']] = $tab_; else $tabs_[count($tabs_) + 1] = $tab_; } ksort($tabs_); // Show the tabs $npmenu = ''; foreach ($tabs_ as $tab) { if ($tab['module'] == $this->page[1] || ($tab['module'] == 'projects' && $this->page[1] == 'project') || ($tab['module'] == 'index' && $this->page[1] != 'project' && !in_array($this->page[1], $modlist))) $npmenu .= '<li><a href="'.htmlspecialchars($tab['link']). '" id="current">'.htmlspecialchars($tab['title']). '</a></li>'; else $npmenu .= '<li><a href="'.htmlspecialchars($tab['link']). '">'.htmlspecialchars($tab['title']).'</a></li>'; } $temp['tpl:notepadmenu'] = $npmenu; // Set global values $temp['slogan'] = $this->slogan; $v = file_get_contents(CT_BASEDIR.'/VERSION'); $temp['poweredby'] = i18n('Powered by CodingTeam %(version)s', array('version' => '<strong>'.$v.'</strong>')); $temp['link_about'] = i18n('About'); $temp['link_tou'] = i18n('Terms of Use'); $temp['link_admin'] = i18n('Administration'); // Set global views if (array_key_exists('head_member', $head)) { ob_start(); $head['head_member']->getPageContent(); $temp['view:head_member'] = ob_get_clean(); } if (array_key_exists('head_search', $head)) { ob_start(); $head['head_search']->getPageContent(); $temp['view:head_search'] = ob_get_clean(); } // Set page Meta-Tags $meta = ''; foreach ($view_loaded->metatags as $key => $value) { switch ($key) { case 'title': $temp['title'] = $value; break; case 'feed': if (!empty($value)) $meta .= '<link rel="alternate" type="application/rss+xml'. '" title="RSS 2.0" href="rss/'.$value.'" />'."\n". ' <link rel="alternate" '. 'type="application/atom+xml" title="Atom 1.0" '. 'href="atom/'.$value.'" />'."\n"; break; case 'javascript': if (is_string($value)) $value = array($value); foreach ($value as $item) $meta .= "<script type='text/javascript' ". "src='".$item."'></script>\n"; break; default: if (!empty($value)) $meta .= ' <meta name="'.$key.'" content="'.$value. '" />'."\n"; } } $temp['htmlmeta'] = $meta; // Load the menu if administration interface if ($is_this_admin) { require_once(CT_BASEDIR.'/inc/modules/admin/menu.php'); $classname = 'AdminMenu'; $menu = new $classname($this->ct_db, $this->lang, $this->ct_session, $this->page); } // Get page menu if (isset($menu)) { $basemenu = $menu->getPageMenu(); $temp['view:pagemenu'] = $basemenu; } else $temp['view:pagemenu'] = ''; // Add infos links $temp['view:infos'] = '<ul>'; if ($this->ct_session->isLogged()) $temp['view:infos'] .= '<li><a href="projects/add">'. i18n('Add a project').'</a></li>'; else $temp['view:infos'] .= '<li><a href="users/register">'. i18n('Register').'</a></li>'; $temp['view:infos'] .= '</ul>'; $cfg = getClass('config', $this->ct_db); // Add the informationbox if ($cfg->get('global', 'show-informationbox')) $temp['tpl:informationbox'] = '<div id="informationbox">'. ' <div id="search">'. ' '.$temp['view:head_search']. ' </div>'. ' <div id="infos">'. ' '.$temp['view:infos']. ' </div>'. ' </div>'; else $temp['tpl:informationbox'] = ''; // Add the page main content $temp['view:pagecontent'] = $page_content; // Finally, stop the execution time here $sec = round(microtime(true) - $this->start_time, 2); $sqlsec = $this->ct_db->getExecutionTime(); if ($cfg->get('global', 'show-exectime')) $temp['execution_time'] = '<span id="exec">'. i18n('Executed in %(sec)d seconds '. '(%(sqlsec)d for SQL).', array('sec' => $sec, 'sqlsec' => $sqlsec)). '</span>'; else $temp['execution_time'] = ''; // Edit the template foreach ($temp as $key => $value) { $search[] = '{'.$key.'}'; $replace[] = $value; } $this->tpl_show = str_replace($search, $replace, $this->tpl_file); return array('content' => $this->tpl_show, 'expire' => $time_expire); } } ?>

CodingTeam