00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00054 function regex_replace($line)
00055 {
00056 $patterns =
00057 array(
00058
00059 "#(?<!\\\\|\[)\[(([^\]]*->[^\]]*)?\s*(\(.*\))?)\s*\]#e",
00060
00061
00062 "#(?<!\\\\|\[)\[>([^\]]*)\]#",
00063
00064
00065 "#(?<!\\\\|\[)\[<([^\]<]*)(<([^<]*))?(<([^\]]*))?\]#e",
00066
00067
00068 "#(?<!\\\\|\[)\[([^\]]+)>([^\]]*)\]#",
00069
00070
00071 "#(?<!\\\\|\[)\[/([^\]]+)\]#",
00072
00073
00074 "#(?<!\\\\|\[)\[([^\]]+)\]#",
00075
00076
00077 "#(?<!\\\\)`(.+?)(?<!\\\\)`#",
00078
00079
00080 "#(?<!\\\\)~(.+?)(?<!\\\\)~#",
00081
00082
00083 "#(?<!\\\\)_(.+?)(?<!\\\\)_#",
00084
00085
00086 "/^(\s*)(.*?)\s*(?<!\\\\)!#\s*(.*?)(\s*)\$/",
00087
00088
00089 "/^(\s*)(?<!\\\\)(bash\\\$|bash#)\s+(.*?)(\s*)\$/",
00090
00091
00092 "#\\\\\[([^\]]+)\]#",
00093
00094
00095 "/\\\\</",
00096
00097
00098 "/\\\\>/",
00099
00100
00101 "/\\\\!#/",
00102
00103
00104 "/^(\s*)\\\\(bash\\\$|bash#)/",
00105
00106
00107 "/\\\\(_|`|~)/",
00108 );
00109
00110 $replacements =
00111 array(
00112
00113 "convert_menu_items('\\1')",
00114
00115
00116 '<xref linkend="\\1"/>',
00117
00118
00119 "mediaobject('\\1', '\\3', '\\5')",
00120
00121
00122 '<ulink url="\\2">\\1</ulink>',
00123
00124
00125 '<footnote><para>\\1</para></footnote>',
00126
00127
00128 '<ulink url="\\1"/>',
00129
00130
00131 '<command>\\1</command>',
00132
00133
00134 '<filename>\\1</filename>',
00135
00136
00137 '<emphasis>\\1</emphasis>',
00138
00139
00140 '\\1<prompt>\\2</prompt> <command>\\3</command>\\4',
00141
00142
00143 '\\1<prompt>\\2</prompt> <command>\\3</command>\\4',
00144
00145
00146 '[\\1]',
00147
00148
00149 '&lt;',
00150
00151
00152 '&gt;',
00153
00154
00155 '!#',
00156
00157
00158 '\\1\\2',
00159
00160
00161 '\\1',
00162 );
00163
00164 $line = preg_replace($patterns, $replacements, $line);
00165 return $line;
00166 }
00167
00182 function convert_menu_items($str)
00183 {
00184 $pos = strpos($str, '(');
00185 if ($pos===false)
00186 {
00187 $menu_path = $str;
00188 $shortcut = '';
00189 }
00190 else
00191 {
00192 $menu_path = substr($str, 0, $pos);
00193 $shortcut = substr($str, $pos + 1);
00194
00195 $pos = strpos($shortcut, ')');
00196 if ($pos) $shortcut = substr($shortcut, 0, $pos);
00197 }
00198 $menu_path = trim($menu_path);
00199 $shortcut = trim($shortcut);
00200
00201 $arr_menu = explode('->', $menu_path);
00202 $arr_keys = explode('-', $shortcut);
00203
00204
00205 for ($i=0; $i < sizeof($arr_menu); $i++)
00206 {
00207 $item = trim($arr_menu[$i]);
00208 if ($item!='') $item_cnt++;
00209 }
00210
00211
00212 if ($menu_path=='') $mchoice = false;
00213 else if ($item_cnt==1 and $shortcut=='') $mchoice = false;
00214 else $mchoice = true;
00215
00216 $xml = '';
00217 if ($mchoice) $xml .= '<menuchoice>';
00218 if ($shortcut!='')
00219 {
00220 if ($mchoice) $xml .= '<shortcut>';
00221 $xml .= '<keycombo>';
00222 for ($i=0; $i < sizeof($arr_keys); $i++)
00223 {
00224 $key = trim($arr_keys[$i]);
00225 $xml .= '<keycap>'.$key.'</keycap>';
00226 }
00227 $xml .= '</keycombo>';
00228 if ($mchoice) $xml .= '</shortcut>';
00229 }
00230 if ($menu_path!='')
00231 {
00232 for ($i=0; $i < sizeof($arr_menu); $i++)
00233 {
00234 $item = $arr_menu[$i];
00235 $item = preg_replace('/(.)_/', '<accel>\\1</accel>', $item);
00236 $item = trim($item);
00237 if ($item=='') continue;
00238
00239 if ($i==0)
00240 $xml .= '<guimenu>'.$item.'</guimenu>';
00241 else if ($i==(sizeof($arr_menu)-1))
00242 $xml .= '<guimenuitem>'.$item.'</guimenuitem>';
00243 else
00244 $xml .= '<guisubmenu>'.$item.'</guisubmenu>';
00245 }
00246 }
00247 if ($mchoice) $xml .= '</menuchoice>';
00248
00249 return $xml;
00250 }
00251
00253 function mediaobject($filename, $width ='', $alt ='')
00254 {
00255
00256 $widthparam = ($width=='' ? '' : "width=\"$width\"");
00257 $str = "
00258 <mediaobject>
00259 <imageobject><imagedata fileref=\"$filename\" $widthparam align=\"center\"/></imageobject>
00260 <textobject><phrase>$alt</phrase></textobject>
00261 </mediaobject>
00262 ";
00263 return $str;
00264 }
00265 ?>