cffe5555b3c36ea5dbeae45b41d11b184c22960f
[atutor.git] / mods / wiki / plugins / mpi / mpi_insert.php
1 <?php
2
3 /*
4    This mpi allows you to insert another wikipage into the current
5    one using <?plugin Insert ThisWikiPage ?>. You can also temporarily
6    change some rendering parameters, by supplying them as optional
7    parameters:
8      <?plugins insert PageName split_title=0 control_line=0 ?>
9
10    The table=0 parameter would disable the optional table+border
11    around the inserted page:
12      <?plugins insert PageName table=0 ?>
13
14    Please note, that the inserted page will be requested through
15    an "sub-request" with ewiki_page(), thus usually incorporating
16    all settings from the main page.
17    
18    As additional extension, you can have a split view (vertical) with
19    multiple pages:
20      <?plugins insert PageOne PageTwo  ?>
21 */
22
23   # you can disable the <table> generation, if you style pages via CSS
24 define("EWIKI_MPI_INSERT_TBL", 1);
25
26
27 $ewiki_plugins["mpi"]["insert"] = "ewiki_mpi_insert";
28 $ewiki_config["mpi_insert"] = array(
29    "table" => EWIKI_MPI_INSERT_TBL,
30 );
31
32
33 function ewiki_mpi_insert($action="html", $args, &$iii, &$s) {
34
35    global $ewiki_config;
36
37    #-- save environment
38    $save = array(
39       "id", "config", "title", "ring", "author",
40    );
41    unset($prevG);
42    $prevG = array();
43    foreach ($save as $name) {
44       $prevG["$name"] = $GLOBALS["ewiki_$name"];
45    }
46
47    #-- use any params as _config settings
48    $args = $args + $ewiki_config["mpi_insert"];
49    foreach ($args as $set=>$val) {
50       if ($set != "_") { 
51          $ewiki_config[$set] = $val;
52       }
53    }
54
55    #-- render requested page, through sub-request
56    $o = array();
57    $o[] = ewiki_page($args["id"]);
58    for ($n=1; $n<=10; $n++) {
59       if ($id = $args[$n]) {
60          $o[] = ewiki_page($id);
61       }
62    }
63
64    #-- reset env
65    foreach ($save as $name) {
66       $GLOBALS["ewiki_$name"] = $prevG[$name];
67    }
68
69    #-- mk table around output
70    $on = count($o);
71    if ($args["table"] || ($on >= 2)) {
72       $o = implode("</td>\n<td valign=\"top\">", $o);
73       $o = '<table border="'.$args["table"].'" cellpadding="5" cellspacing="5">'
74       // . '<colgroups>' . str_repeat('<col width="'.((int)(100/$on)).'%" />', $on) . '</colgroups>'
75          . '<tr><td valign="top">' . $o . '</td></tr></table>';
76    }
77    else {
78       $o = implode("\n<br /><!-- cut-here --><br />\n", $o);
79    }
80    $o = '<div class="mpi-insert">' . $o . '</div>';
81
82    return($o);
83 }
84
85 ?>