'editfck', 'Width' => '100%', 'Height' => '400', 'BaseImagePath' => 'http://'.$_SERVER[HTTP_HOST], 'BasePath' =>'/wiki/pub/fckeditor/FCKeditor/', 'UserFilesPath' => '/wiki/uploads/', 'ToolBar'=> 'PmWiki', 'EditorAreaCSS' => '/wiki/pub/fckeditor/pm_fckstyles.css', 'StylesXmlPath' => '/wiki/pub/fckeditor/pm_fckstyles.xml', 'CustomConfigurationsPath' => '/wiki/pub/fckeditor/pm_fckconfig.js', 'TextTranslation' => array(summary => 'Summary:', author => 'Author:', minor => 'This is a minor edit', editfck => "WysIsWyg Edit") )); SDVA($HandleActions,array($PmFCK['EditFckAction'] => 'HandleEditFck')); SDVA($HandleAuth,array($PmFCK['EditFckAction'] => 'edit')); SDVA($MarkupToDisable, array(count($MarkupToDisable) =>'if', 'redirect', 'include', 'nogroupfooter', 'nogroupheader', 'groupheader', 'groupfooter', 'noright', 'noleft', 'notitle', 'nofooter', 'noaction', 'spacewikiwords', 'messages', 'linebreaks', 'linkwikiwords', 'noheader', 'varindex', 'pagelist', 'searchresults', 'input', 'comment', 'title')); function HandleEditFck($pagename, $auth = 'edit') { global $IsPagePosted, $EditFields, $ChangeSummary, $EditFunctions, $EnablePost, $EnablePostAuthorRequired, $FmtV, $Now, $EditRedirectFmt, $Author, $PageEditForm, $HandleEditFmt, $PageStartFmt, $PageEditFmt, $PageEndFmt,$PmFCK,$MarkupToDisable,$MarkupTable,$MarkupRules,$MessagesFmt; SDV($EditRedirectFmt, '$FullName'); if (@$_POST['cancel']) { Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; } Lock(2); $IsPagePosted = false; $page = RetrieveAuthPage($pagename, $auth, true); if (!$page) Abort("?cannot edit $pagename"); PCache($pagename,$page); $new = $page; if (isset($_POST['FCKeditor1'])) $new['text']=HTMLToMarkups($pagename,str_replace("\r",'',stripmagic($_POST['FCKeditor1']))); $new['csum'] = $ChangeSummary; if ($ChangeSummary) $new["csum:$Now"] = $ChangeSummary; $EnablePost &= preg_grep('/^post/', array_keys(@$_POST)); // $Editfunctions if (IsEnabled($EnablePostAuthorRequired,0)) { RequireAuthor($pagename, $page, $new); } SaveAttributes($pagename,$page,$new); PostPage($pagename,$page,$new); PostRecentChanges($pagename,$page,$new); Lock(0); if ($IsPagePosted && !@$_POST['postedit']) { Redirect(FmtPageName($EditRedirectFmt, $pagename)); return; } $FmtV['$DiffClassMinor'] = (@$_POST['diffclass']=='minor') ? "checked='checked'" : ''; $FmtV['$EditText'] = str_replace('$','$',htmlspecialchars(@$new['text'],ENT_NOQUOTES)); $FmtV['$EditBaseTime'] = $Now; /* if (@$PageEditForm) { $form = ReadPage(FmtPageName($PageEditForm, $pagename), READPAGE_CURRENT); // $FmtV['$EditForm'] = MarkupToHTML($pagename, $form['text']); }*/ // Config $oFCKeditor = new FCKeditor('FCKeditor1'); $oFCKeditor->Config['EditorAreaCSS'] = $PmFCK['EditorAreaCSS']; $oFCKeditor->Config['StylesXmlPath'] = $PmFCK['StylesXmlPath']; $oFCKeditor->Config['CustomConfigurationsPath'] = $PmFCK['CustomConfigurationsPath']; $oFCKeditor->BasePath = $PmFCK['BasePath']; $oFCKeditor->Width = $PmFCK['Width']; $oFCKeditor->Height = $PmFCK['Height'] ; $oFCKeditor->Config['ToolBar'] = $PmFCK['ToolBar']; $TmpMarkupTable=$MarkupTable; // Disable selected markups during the conversion $TmpMarkupRules=$MarkupRules; DisableMarkup($MarkupToDisable); $html= MarkupToHTML($pagename,$new['text']); // Convert Wiki Markups to normal HTML, using the standard fonction $html = preg_replace("/]*)><\/div>/i", "",$html); // Remove some stuff that causes problem when translating from HTML to Wiki after the edit $html = preg_replace("/]*)><\/p>/i", "",$html); $MarkupTable=$TmpMarkupTable; // Restore the markups for the page to be properly displayed $MarkupRules=$TmpMarkupRules; $oFCKeditor->Value = $html; $PageEditFmt= "

$[Editing {\$FullName}]

".$MessagesFmt[0]." ".$oFCKeditor->CreateHtml(). "
".$PmFCK['TextTranslation']['summary']."
".$PmFCK['TextTranslation']['author']." ".$PmFCK['TextTranslation']['minor']."
"; SDV($HandleEditFmt, array(&$PageStartFmt, &$PageEditFmt , &$PageEndFmt)); PrintFmt($pagename, $HandleEditFmt); // } function HTMLToMarkups($pagename,$html) { global $HTML_Markups,$ScriptUrl; // Delete all the \r\n ibetween markups to avoid problem when converting table markups // This has to be done before replacement of non-block markups, which mays produces compulsory \r\n inside a cell for example $html = preg_replace_callback("/([ ]*<[\/]{0,1}(table|thead|tbody|tr|th|td){1}[^>]*>[\r\n]*)/i", "LinesBreaksRemove" ,$html ); // Replacement of all non-block markups foreach ($HTML_Markups as $markup => $attributes) { if (isset($attributes['alias'])) $attributes=$HTML_Markups[$attributes['alias']]; if (@$attributes['type'] == 'single') $html = preg_replace("/<$markup([^>]*)>/i", @$attributes['start'], $html); if (@$attributes['type'] == 'noattr') $html = preg_replace("/<$markup([^>]*)>(.*?)<\/$markup>/i", @$attributes['start']."$2".@$attributes['end'], $html); if (@$attributes['type'] == 'attr') { preg_match_all("/<$markup(([ ]*[a-zA-Z]+=[\"'](.*?)[\"'])*?)[ ]*>(.*?)<\/$markup>/i", $html , $matches); // [ ]?([a-zA-Z]+='(.+?)') $strmatch = $matches[0]; $markup_attr = $matches[1]; $markup_txt = $matches[4]; $i=0; while ($i]+?)[\"']/",$markup_attr[$i],$attr_match); list($tmp,$markup_listattr,$markup_listparam)=$attr_match; $j=0; $attrisset=0; while ($j markup - nothing else !! { preg_match_all("/(.*?)<\/a>/i", $html , $matches); // [ ]?([a-zA-Z]+='(.+?)') $strmatch = $matches[0]; $markup_attr = $matches[1]; $markup_txt = $matches[4]; $i=0; while ($i]+?)[\"|']/",$markup_attr[$i],$attr_match); list($tmp,$markup_listattr,$markup_listparam)=$attr_match; $j=0; while ($j local link eregi("[a-z]+[/\.]{1}[a-z]+$",$linkparam['href'],$page); // Check if the link as a text description or if it's just the pagename if ($page[0]==trim($markup_txt[$i])) $wikilink=$attributes['normal']['start'].$page[0].$attributes['normal']['end']; else $wikilink=$attributes['normal']['start'].$page[0].$attributes['normal']['middle'].$markup_txt[$i].$attributes['normal']['end']; // Normal Url } else $wikilink=$attributes['normal']['start'].$linkparam['href'].$attributes['normal']['middle'].$markup_txt[$i].$attributes['normal']['end']; // Normal Url } else if (isset($linkparam['name']) || isset($linkparam['id'])) { // Anchor $linkparam['name'] = ($linkparam['name']!='') ? $linkparam['name']:$linkparam['id']; if (trim($markup_txt[$i])!="") $wikilink = $attributes['anchor']['middle'] . $markup_txt[$i]; $wikilink = $attributes['anchor']['start'].$linkparam['name'].$wikilink.$attributes['anchor']['end']; } else { /* Unknow ? - do nothing */ } if (@$linkparam['target']=='_blank') $wikilink = @$attributes['newwin']['start']. $wikilink . @$attributes['newwin']['end']; $html=str_replace($strmatch[$i],$wikilink,$html); $i++; } } // End of "if (@$attributes['type'] == 'link')" } // List markups $html = preg_replace_callback("/([ ]*<[\/]{0,1}(ul|ol|li){1}>?)/i", "ListMarkupReplace" ,$html ); // Table markups $html = preg_replace_callback("/[ ]*<([\/]{0,1})(table|tr|th|td)([^>]*)>/i", "TableMarkupReplace" ,$html ); // Img markups $html = preg_replace_callback("/[ ]*]*)>/i", "ImgMarkupReplace" ,$html ); // Avoid space to become too present $html = str_replace(" ", " ",$html); // Remove non recognized markups $html = strip_tags ($html); return $html; } SDV($ListDepth,0); SDV($BulletType,''); function ListMarkupReplace($matches) { global $ListDepth,$BulletType; $ret_html=''; $ListBullets = array( 'ul' => '*', 'ol' => '#', 'dl' => ':'); switch (trim($matches[0])){ case "
  • ": $ret_html=str_repeat($BulletType, $ListDepth); break; case "
  • ": $ret_html=""; break; case "
      ": $ListDepth++; $BulletType = $ListBullets['ul']; break; case "
        ": $ListDepth++; $BulletType = $ListBullets['ol']; break; case "
        ": $ListDepth++; $BulletType = $ListBullets['dl']; break; case "
    ": $ListDepth--; break; case "": $ListDepth--; break; case "": $ListDepth--; break; } return $ret_html; } SDV($NewLineCreated,0); // Set to 1 if a
    has just been matched, to display a (:cellnr:) instead of a (:cellr:) function TableMarkupReplace($matches) { global $HTML_Markups,$NewLineCreated; $ret_html=''; $opclose=$matches[1]; $markup=$matches[2]; $params=$matches[3]; if (trim($params)!="" && $opclose != "/") { preg_match_all("/([a-zA-Z]+?)=[\"|']([^\"'>]+?)[\"|']/",$params,$attr_match); $i=0; while ($i$attr_val) { if (in_array($attr_name,$HTML_Markups[$markup]['autorizedparam'])) $wikiparam.=" $attr_name=$attr_val"; } } else $wikiparam=""; if ($opclose=="") { switch ($markup) { case "table": $ret_html="(:table$wikiparam:)\r\n"; break; case "tr": $NewLineCreated=1; break; case "th": $ret_html= ($NewLineCreated==1) ? "(:cellnr$wikiparam:)" : "(:cell$wikiparam:)"; $NewLineCreated=0; break; case "td": $ret_html= ($NewLineCreated==1) ? "(:cellnr$wikiparam:)" : "(:cell$wikiparam:)"; $NewLineCreated=0; break; } } else { switch ($markup) { case "table": $ret_html="(:tableend:)\r\n"; break; case "th": $ret_html="\r\n"; break; case "td": $ret_html="\r\n"; break; } } return $ret_html; } function ImgMarkupReplace($matches) { global $HTML_Markups,$PmFCK; $ret_html=''; preg_match_all("/([a-zA-Z]+?)=[\"|']([^\"'>]+?)[\"|']/",$matches[1],$attr_match); $i=0; while ($i$attr_val) { if (in_array($attr_name,$HTML_Markups['img']['autorizedparam'])) $wikiparam.=" $attr_name=$attr_val"; } $wikialt = ($listattr['alt']!='') ? "\"$listattr[alt]\"":''; $wikiparam=trim($wikiparam); $ret_html="%$wikiparam%$wikisrc$wikialt"; } return $ret_html; } function LinesBreaksRemove($matches) { return str_replace("\r\n","",trim($matches[0])); } /* $HTML_Markups : type attribute - noattr : direct replacement - the markup doesn't have significant attributes - attr : replacement may change depending of markup attributes (ex class, style) - single : it's a single markup. There isn't an openning markup and a closing one with some stuff between */ $HTML_Markups = array( 'b' => array( 'start' => "'''", 'end' => "'''" , 'type' => 'noattr'), 'strong' => array( 'alias' => 'b' ), 'i' => array( 'start' => "''", 'end' => "''", 'type' => 'noattr' ), 'em' => array( 'alias' => 'i' ), 'tt' => array( 'start' => '@@', 'end' => '@@', 'type' => 'noattr' ), 'code' => array( 'alias' => 'tt' ), 'small' => array( 'start' => "'+", 'end' => "+'", 'type' => 'noattr' ), 'big' => array( 'start' => "'-", 'end' => "-'", 'type' => 'noattr' ), 'sup' => array( 'start' => "'^", 'end' => "^'", 'type' => 'noattr' ), 'sub' => array( 'start' => "'_", 'end' => "_'", 'type' => 'noattr' ), 'ins' => array( 'start' => '{+', 'end' => '+}', 'type' => 'noattr' ), 'u' => array( 'alias' => 'ins'), 'del' => array( 'start' => '{-', 'end' => '-}', 'type' => 'noattr' ), 'strike' => array( 'alias' => 'del'), 'p' => array( 'type' => 'attr', 'attr_class' => array( 'vspace' => array ('start' => "", 'end' => "\r\n\r\n"), 'default' => array ('start' => '%p class=$param%', 'end' => "%%\r\n\r\n")), 'attr_align' => array( 'justify' => array ('start' => "%block text-align=justify%", 'end' => "%%\r\n\r\n"), 'center' => array ('start' => "%block text-align=center%", 'end' => "%%\r\n\r\n"), 'right' => array ('start' => "%block text-align=right%", 'end' => "%%\r\n\r\n"), 'default' => array ('start' => "", 'end' => "\r\n\r\n")), 'attr_style' => array ('text-align: center;' => array ('start' => "%block text-align=center%", 'end' => "%%\r\n\r\n"), 'default' => array ('start' => "", 'end' => "\r\n\r\n")), 'no_attr_def' => array( 'start' => "", 'end' => "\r\n\r\n")), 'div' => array( 'type' => 'attr', 'attr_class' => array( 'vspace' => array ('start' => "", 'end' => "\r\n\r\n"), 'default' => array ('start' => "", 'end' => "\r\n\r\n")), 'attr_align' => array( 'justify' => array ('start' => "%block text-align=justify%", 'end' => "%%\r\n\r\n"), 'center' => array ('start' => "%block text-align=center%", 'end' => "%%\r\n\r\n"), 'right' => array ('start' => "%block text-align=right%", 'end' => "%%\r\n\r\n"), 'default' => array ('start' => "", 'end' => "\r\n\r\n")), 'no_attr_def' => array( 'start' => "", 'end' => "\r\n\r\n")), 'span' => array( 'type' => 'attr', 'attr_class' => array( 'wikiword' => array ('start' => "", 'end' => ""), 'default' => array ('start' => '%class=$param%', 'end' => "%%")), 'attr_style' => array( 'font-size: 144%;' => array ('start' => "[++", 'end' => "++]"), // Need to translate the 'font-size: 120%;' => array ('start' => "[+", 'end' => "+]"), // size markups of PmWiki 'font-size: 83%;' => array ('start' => "[-", 'end' => "-]"), // 'font-size: 69%;' => array ('start' => "[--", 'end' => "--]"), // 'default' => array ('start' => "", 'end' => "")), 'no_attr_def' => array( 'start' => "", 'end' => "")), 'font' => array( 'type' => 'attr', 'attr_size' => array( '1' => array ('start' => "[--", 'end' => "--]"), // Need to translate the size '2' => array ('start' => "[-", 'end' => "-]"), // bar of FCKEditor '3' => array ('start' => "", 'end' => "-]"), '4' => array ('start' => "[+", 'end' => "+]"), '5' => array ('start' => "[++", 'end' => "++]"), 'default' => array ('start' => "", 'end' => "")), 'no_attr_def' => array( 'start' => "", 'end' => "")), 'h1' => array( 'start' => '! ' , 'end' =>"\r\n", 'type' => 'noattr' ), 'h2' => array( 'start' => '!! ' , 'end' =>"\r\n", 'type' => 'noattr' ), 'h3' => array( 'start' => '!!! ' , 'end' =>"\r\n", 'type' => 'noattr' ), 'h4' => array( 'start' => '!!!! ' , 'end' =>"\r\n", 'type' => 'noattr' ), 'h5' => array( 'start' => '!!!!! ' , 'end' =>"\r\n", 'type' => 'noattr' ), 'h6' => array( 'start' => '!!!!!! ' , 'end' =>"\r\n", 'type' => 'noattr' ), 'br' => array( 'start' => "\\\\\\\r\n", 'type' => 'single' ), 'hr' => array( 'start' => '----' , 'type' => 'single' ), 'a' => array( 'type' => 'link', 'normal' => array('start' => '[[', 'middle' =>'|', 'end' =>']]'), // standard link [[link|text]] 'raw_url' => array('start' => '', 'middle' =>'', 'end' =>''), // only an url 'newwin' => array('start' => '%newwin%'), // add %newwin% is target='_blank' is found 'anchor' => array('start' => '[[#', 'middle' =>'|', 'end' =>']]')), // anchor link [[#anchor]] or [[#anchor|text]] 'table' => array( 'type' => 'block', 'autorizedparam' => array('border', 'bordercolor', 'cellspacing', 'cellpadding', 'width', 'bgcolor', 'align', 'summary')), 'td' => array( 'type' => 'block', 'autorizedparam' => array('align', 'valign', 'colspan', 'rowspan', 'bgcolor', 'width')), 'tbody' => array( 'start' => "", 'end' => "" , 'type' => 'noattr'), // "Unuseful" Markups : not translated in PmWiki 'thead' => array( 'start' => "", 'end' => "" , 'type' => 'noattr'), 'tbody' => array( 'start' => "", 'end' => "" , 'type' => 'noattr'), 'img' => array( 'type' => 'block', 'autorizedparam' => array('width', 'height', 'border', 'vspace', 'hspace')) ); ?> Redirect