markupend',
"/\\(:sourcehistory(\\s+.*?)?\\s*:\\)[^\\S\n]*\\[([=@])(.*?)\\2\\]/sei",
"SourceHistoryMarkup(\$pagename, PSS('$1'), PSS('$3'))");
Markup('sourcehistoryend', '>sourcehistory',
"/\\(:sourcehistory(\\s+.*?)?\\s*:\\)[^\\S\n]*\n(.*?)\\(:sourcee?nd:\\)/sei",
"SourceHistoryMarkup(\$pagename, PSS('$1'), PSS('$2'))");
function SourceHistoryMarkup($pagename, $args, $block) {
// copie à peine modifiée du code de D. Faure, SourceBlockMarkup
//insère un code formaté pmwiki
global $SourceHistoryParams, $GESHI_PATH, $HTMLStylesFmt, $GeshiStyles,
$GeshiConfig, $SourceHistoryFmt, $SourceHistoryDivNumber,
$EnableSourceHistoryKeywordLinks;
SDVA($SourceHistoryParams, array('header' => '', 'footer' => ''));
$opt = array_merge((array)$SourceHistoryParams, ParseArgs($args));
$getcode = SourceBlockGetCodeInit($pagename, $opt);
if(!@in_array('trim', (array)$opt['-'])) $block = trim($block);
if(@$opt['lang']) {
include_once($GESHI_PATH . "/geshi.php");
# undo PmWiki's htmlspecialchars conversion
$block = str_replace(array('<:vspace>', '<', '>', '&'),
array('', '<', '>', '&'), $block);
$geshi =& new GeSHi($block, $opt['lang'], GESHI_LANG_ROOT);
$geshi->enable_classes();
SDVA($GeshiStyles, array(
'code' => 'font-family: monospace; font-weight: normal;',
'line1' => 'font-family: monospace; color: black; font-weight: normal;',
'line2' => 'font-weight: bold;',
));
$geshi->set_code_style($GeshiStyles['code']);
$geshi->set_line_style($GeshiStyles['line1'], $GeshiStyles['line2']);
$geshi->set_header_type(GESHI_HEADER_DIV);
if(@$opt['tabwidth']) $geshi->set_tab_width($opt['tabwidth']);
if(@in_array('strict', (array)$opt['']))
$geshi->enable_strict_mode();
if(@in_array('linenum', (array)$opt['']))
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
if(@$opt['linenum']) {
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
$geshi->start_line_numbers_at($opt['linenum']);
}
if(@$opt['highlight']) {
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
$geshi->highlight_lines_extra(preg_split("/[\\s,;]+/", $opt['highlight']));
}
if(@$opt['encoding']) $geshi->set_encoding($opt['encoding']);
$geshi->set_header_content($opt['header']);
$geshi->set_footer_content($opt['footer']);
$links = IsEnabled($EnableSourceHistoryKeywordLinks, false);
if( @in_array('link', (array)$opt['-'])) $links = false;
elseif(@in_array('link', (array)$opt['+'])) $links = true;
$geshi->enable_keyword_links($links);
if($GeshiConfig) $GeshiConfig($pagename, $geshi, $args);
@$HTMLStylesFmt['geshi_'.$geshi->overall_class.'_'.$geshi->overall_id] = $geshi->get_stylesheet();
$txt = $geshi->parse_code();
if($geshi->error()) $txt = $geshi->error();
} else {
$lines = explode("\n", $block);
$count = count($lines);
$linenum = "";
if(@in_array('linenum', (array)$opt[''])) $linenum = "
";
elseif(@$opt['linenum']) $linenum = "";
$txt = "";
for($i = 0; $i < $count; $i++)
$txt .= ($linenum ? "- " : "") . $lines[$i] . ($linenum ? "
" : "
");
$txt = "{$linenum}{$txt}" . ($linenum ? "" : "") . "
";
}
SDV($SourceHistoryFmt, "
");
// Insertion of new code (SourceHistory)
$name = PageVar($pagename, '$Name');
$dern = PageVar($lastmodified, '$LastModified');
//The name of the wiki file is converted : upcase to lowcase with underline
$standardname = str_replace('.', '', substr($pagename, strpos($pagename, '.')));
$standardname = ereg_replace('[A-Z]', ' ' . strtolower("\\0"), $standardname);
$standardname = str_replace(' ', '_', trim(strtolower($standardname)));
// Here the new files will be located in /prog directory, and the name of the file will include a 'inc.php' extension
$filename = "prog/$standardname.inc.php";
if( ! $fp = fopen($filename, 'w')) {
echo "
Échec de l'ouverture du fichier $filename";
} else {
fputs($fp, $block);
fclose($fp);
}
// End of the new SourceHistory code
SDV($HTMLStylesFmt['sourcehistory'], "
.sourcehistorylink {
text-align: right;
font-size: smaller;
}
.sourcehistorytext {
padding: 0.5em;
border: 1px solid #808080;
color: #000000;
background-color: #f1f0ed;
}
.sourcehistorytext div {
font-family: monospace;
font-size: small;
line-height: 1;
height: 1%;
}
.sourcehistorytext div.head,
.sourcehistorytext div.foot {
font: italic medium serif;
padding: 0.5em;
}
");
// l'insertion marche ici, mais est vide
return Keep(str_replace(
array('$class', '$id', '$url', '$txt'),
array(@$opt['class'],
IsEnabled($opt['id'], 'sourcehistory'.$SourceHistoryDivNumber),
$getcode ? SourceBlockGetCodeHandler($pagename, $opt, $block) : '',
$txt),
$SourceHistoryFmt));
// l'insertion ne marche pas ici
}
/* svg de l'insertion
//global $pagename;
//global $lastmodified;
$name = PageVar($pagename, '$Name');
//echo "
Nom du fich : $name";
$dern = PageVar($lastmodified, '$LastModified');
//echo "
Dern modif du fich : $dern";
//$n = PageVar('$Name', $pagename);
//$n = PageVar('$LastModified', $lastmodified);
//$standardname = str_replace('.', '', substr($pagename, strpos($pagename, '.')));
$standardname = str_replace('.', '', substr($pagename, strpos($pagename, '.')));
$nom1 = ereg_replace('[A-Z]', ' ' . strtolower("\\0"), $standardname);
$nom2 = ereg_replace('([A-Z])', '_' . strtolower("\0"), $standardname);
$nom3 = ereg_replace("(^[^A-Z])([A-Z])", "\\0_\\1", $standardname);
$nom4 = ereg_replace("^[^A-Z]([A-Z])", "\\0_\\1", $standardname);
//echo "
noms 1, 2, 3, 4 : $nom1, $nom2, $nom3, $nom4";
$standardname = str_replace(' ', '_', trim(strtolower($nom1)));
//$standardname = ereg_replace("([A-Z]) ", "\\1", ucwords(strtolower(ereg_replace("[A-Z]"," \\0", $standardname))));
//$standardname = ereg_replace("([A-Za-z])([0-9])", "\\1 \\2", $standardname);
$filename = "prog/$standardname.inc.php";
if (file_exists($filename)) {
//echo "$filename a été modifié le : " . date ("F d Y H:i:s.", filemtime($filename));
}
if( ! $fp = fopen($filename, 'w')) {
//echo "
Échec de l'ouverture du fichier $filename";
} else {
fputs($fp, $block);
fclose($fp);
}
*/