*/
class action_plugin_ckgedit_edit extends DokuWiki_Action_Plugin {
var $fck_location = "ckeditor";
var $helper = false;
var $ckgedit_bak_file = "";
var $debug = false;
var $test = false;
var $page_from_template;
var $draft_found = false;
var $draft_text;
var $draft_started;
var $captcha;
/**
* Constructor
*/
function __construct()
{
$this->setupLocale();
$this->helper = plugin_load('helper', 'ckgedit');
if(!plugin_isdisabled('captcha')) {
$this->captcha = plugin_load('helper', 'captcha');
}
else $this->captcha = false;
}
function register(Doku_Event_Handler $controller)
{
global $INPUT;
$version = explode('.', phpversion());
define('PHP_VERSION_NUM', $version[0] * 10+ $version[1]);
if($this->helper->is_outOfScope()) return;
global $FCKG_show_preview;
$FCKG_show_preview = true;
if(isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'dwiki') {
$FCKG_show_preview = true;
return;
}
elseif(isset($_COOKIE['FCKG_USE'])) {
preg_match('/_\w+_/', $_COOKIE['FCKG_USE'], $matches);
if($matches[0] == '_false_') {
$FCKG_show_preview = true;
return;
}
}
$Fck_NmSp = "!!NONSET!!";
if(isset($_COOKIE['FCK_NmSp'])) {
$Fck_NmSp = $_COOKIE['FCK_NmSp'];
}
$dwedit_ns = $this->getConf('dwedit_ns');
if(isset($dwedit_ns) && $dwedit_ns) {
$ns_choices = explode(',',$dwedit_ns);
foreach($ns_choices as $ns) {
$ns = trim($ns);
$id = $INPUT->str('id');
if(($id && preg_match("/$ns/",$id)) || ($Fck_NmSp && preg_match("/$ns/",$Fck_NmSp))) {
$FCKG_show_preview = true;
return;
}
}
}
$controller->register_hook('COMMON_PAGE_FROMTEMPLATE', 'AFTER', $this, 'pagefromtemplate', array());
$controller->register_hook('COMMON_PAGETPL_LOAD', 'AFTER', $this, 'pagefromtemplate', array());
$controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'ckgedit_edit');
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'ckgedit_edit_meta');
}
/**
* function pagefromtemplate
* Capture template text output by Template Event handler instead of pageTemplate()
* @author Myron Turner \s*)*( |\s+)<\/p>/",$tmp[$n])) || (preg_match("/^\s+$/",$tmp[$n]))) {
unset($tmp[$n]);
}
}
return "~~START_HTML_BLOCK~~" . implode("\n",$tmp) . "CLOSE_HTML_BLOCK";
},$this->xhtml);
$this->xhtml = preg_replace_callback(
'/( \s* \s+_ckgedit_NPBBR_\s+<\/p>/ms',"\n",$xhtml);
$xhtml = str_replace('_ckgedit_NPBBR_', " ", $xhtml);
$xhtml = str_replace('_ckgedit_QUOT_', '"', $xhtml);
$xhtml = str_replace('_ckgedit_NL', "\n", $xhtml);
$xhtml = str_replace(' |/ms", "TPRE_CODE", $matches[2]);
$matches[2] = preg_replace("/(.*?<\/code>)|ms',
function($matches) {
$retstr = $matches[1] . ">\n/*" . $matches[2] . "*/\n" . $matches[3];
return $retstr;
}, $text
);
$this->xhtml = $this->_render_xhtml($text);
/*interwiki frasl refactoring*/
// $this->xhtml = str_replace("__IWIKI_FSLASH__", "⁄", $this->xhtml);
if($this->getConf('duplicate_notes')) {
$this->xhtml = preg_replace("/FNoteINSert\d+/ms", "",$this->xhtml);
}
if($divalign) {
$this->xhtml = str_replace("CGEHASH", "#", $this->xhtml);
}
$this->xhtml = str_replace("__GESHI_QUOT__", '"', $this->xhtml);
$this->xhtml = str_replace("__GESHI_OPEN__", "< ", $this->xhtml);
$this->xhtml = str_replace('CHEVRONescC', '>>',$this->xhtml);
$this->xhtml = str_replace('CHEVRONescO', '<<',$this->xhtml);
$this->xhtml = preg_replace('/_QUOT_/ms','>',$this->xhtml); // dw quotes
$this->xhtml = preg_replace_callback(
"/^(>+)(.*?)$/ms",
function($matches) {
$matches[2] = str_ireplace('
',"",$matches[2]);
return $matches[1] . $matches[2] . "
";
},
$this->xhtml
);
if($pos !== false) {
$this->xhtml = preg_replace_callback(
'/(TPRE_CODE|TPRE_FILE)(.*?)(TPRE_CLOSE)/ms',
function($matches) {
$matches[1] = preg_replace("/TPRE_CODE/","\n", $matches[1]);
$matches[1] = preg_replace("/TPRE_FILE/","\n", $matches[1]);
$matches[2] = preg_replace("/TC_NL/ms", "\n", $matches[2]);
$matches[3] = "";
return $matches[1] . $matches[2] . $matches[3];
},
$this->xhtml
);
}
$this->xhtml = preg_replace_callback(
'/~~START_HTML_BLOCK~~[\n\s]*(.*?)CLOSE_HTML_BLOCK/ms',
function($matches) {
$matches[1] = str_replace("&","&",$matches[1]);
$matches[1] = html_entity_decode($matches[1],ENT_QUOTES, "UTF-8");
$matches[1] = preg_replace("/<\/?code.*?>/", "",$matches[1]);
$matches[1] = preg_replace("/^\s*<\/p>/","",$matches[1]);
$tmp = explode("\n", $matches[1]);
for($n=0; $n<7; $n++) {
if( (preg_match("/()(.*?)(<\/pre>)/ms',
function($matches) {
$matches[4] = preg_replace("/(\||\^)[ ]+(\||\^)/ms","$1 $2" , $matches[4]);
return $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5];
},
$this->xhtml
);
$this->xhtml = preg_replace_callback(
'/~~MULTI_PLUGIN_OPEN~~(.*?)~~MULTI_PLUGIN_CLOSE~~/ms',
function($matches) {
return str_replace("<", "< ",$matches[0]);
},
$this->xhtml
);
//insures breaks are retained for single spacing
$this->xhtml = preg_replace('/', "\n\n
\s*<\/p>/ms', '
', $this->xhtml);
if($this->draft_started) return $this->xhtml;
$cname = getCacheName($INFO['client'].$ID,'.draft.fckl');
// msg($cname);
$this->draft_started = false;
if(file_exists($cname) && !$this->draft_started) {
$this->draft_started = true;
$cdata = unserialize(io_readFile($cname,false));
$prefix = isset($cdata['prefix']) ? urldecode($cdata['prefix']) : "" ;
if($prefix) $prefix = $this-> _preprocess($prefix);
$text = urldecode($cdata['text']);
$suffix = isset($cdata['suffix']) ? urldecode($cdata['suffix']) : "" ;
if($suffix) $suffix = $this-> _preprocess($suffix);
preg_match_all("/<\/(.*?)\>/", $cdata['text'],$matches);
/* exclude drafts saved from preview mode */
if (!in_array('code', $matches[1]) && !in_array('file', $matches[1]) && !in_array('nowiki', $matches[1])) {
//$this->draft_text = $cdata['text'];
$this->draft_text = $prefix . $text . $suffix;
$this->draft_found = true;
msg($this->getLang('draft_msg')) ;
}
unlink($cname);
}
if($this->draft_started) return $this->xhtml;
return true;
}
/**
Check for for alternate style sheet
*/
function alt_style_sheet() {
$stylesheet = DOKU_PLUGIN . 'ckgedit/ckeditor/css/_style.css';
if(file_exists($stylesheet)) {
global $conf;
$tpl_name = $conf['template'];
if($fh = fopen($stylesheet,"r")) {
$line_num = 0;
while (!feof($fh) && $line_num < 4) {
$line = fgets($fh,1024); //msg($line);
if(strpos($line,$tpl_name)!==false) {
return DOKU_BASE . '/lib/plugins/ckgedit/ckeditor/css/_style.css' ;
break;
}
$line_num ++;
}
}
}
return "";
}
/**
* function _print
* @author Myron Turner
*/
function _print()
{
global $INFO;
global $lang;
global $ckgedit_lang;
global $ID;
global $REV;
global $DATE;
global $PRE;
global $SUF;
global $SUM;
$wr = $INFO['writable'];
if($wr){
if ($REV) print p_locale_xhtml('editrev');
$ro=false;
}else{
// check pseudo action 'source'
if(!actionOK('source')){
msg('Command disabled: source',-1);
return false;
}
print p_locale_xhtml('read');
$ro='readonly="readonly"';
}
if(!$DATE) $DATE = $INFO['lastmod'];
$guest_toolbar = $this->getConf('guest_toolbar');
$guest_media = $this->getConf('guest_media');
if(!isset($INFO['userinfo']) && !$guest_toolbar) {
$toolbar = "DokuwikiNoGuest";
}
else if(!isset($INFO['userinfo']) && !$guest_media) {
$toolbar = "DokuwikiGuest";
}
else $toolbar = 'Dokuwiki';
$height = isset($_COOKIE['ckgEdht']) && $_COOKIE['ckgEdht'] ? $_COOKIE['ckgEdht']: 250;
if(!is_numeric($height)) $height = 250;
$fbsz_increment = isset($_COOKIE['fbsz']) && $_COOKIE['fbsz'] ? $_COOKIE['fbsz'] : false;
$fbrowser_width = 1070;
$fbrowser_height = 660;
if($fbsz_increment) {
$fbrowser_width = $fbrowser_width + ($fbrowser_width*($fbsz_increment/100));
$fbrowser_height =$fbrowser_height + ($fbrowser_height*($fbsz_increment/100));
}
$doku_base= rtrim(DOKU_BASE,'/');
$ns = getNS($_COOKIE['FCK_NmSp']);
//get user file browser if allowed
if ($this->getConf('allow_ckg_filebrowser') == 'all') {
$fb = $this->getUserFb();
} else {
//use only allowed file browser
$fb = $this->getConf('allow_ckg_filebrowser');
}
//setup options
if ($fb == 'dokuwiki') {
$fbOptions = "filebrowserImageBrowseUrl: \"$doku_base/lib/exe/mediamanager.php?ns=$ns&edid=wiki__text&onselect=ckg_edit_mediaman_insert&ckg_media=img\",
filebrowserBrowseUrl: \"$doku_base/lib/exe/mediamanager.php?ns=$ns&edid=wiki__text&onselect=ckg_edit_mediaman_insertlink&ckg_media=link\"";
} else {
$fbOptions = "filebrowserImageBrowseUrl : \"$doku_base/lib/plugins/ckgedit/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=$doku_base/lib/plugins/ckgedit/fckeditor/editor/filemanager/connectors/php/connector.php\",
filebrowserBrowseUrl: \"$doku_base/lib/plugins/ckgedit/fckeditor/editor/filemanager/browser/default/browser.html?Type=File&Connector=$doku_base/lib/plugins/ckgedit/fckeditor/editor/filemanager/connectors/php/connector.php\"";
}
if($this->getConf('style_sheet')) {
$contents_css = $this->alt_style_sheet();
}
else {
$contents_css = "";
}
//msg($contents_css);
$ckeditor_replace =<<|
",$matches[0]);
},
$xhtml
);
$xhtml = preg_replace('/~\s*~\s*MULTI_PLUGIN_OPEN~\s*~/', "\n\n~~MULTI_PLUGIN_OPEN~~\n\n\n\n", $xhtml);
$xhtml = preg_replace('/~\s*~\s*MULTI_PLUGIN_CLOSE~\s*~/', "\n\n
\n\n~~MULTI_PLUGIN_CLOSE~~\n\n", $xhtml);
}
// remove empty paragraph: see _ckgedit_NPBBR_ comment above
$xhtml = preg_replace('/
\s+<\/(em|b|u|i)>/ms',"",$xhtml);
$xhtml = preg_replace("/col\d+\s+(\w+align)/ms", "$1",$xhtml); //remove col number for cell prpoerties dialog
$xhtml = str_replace('ckgeditFONTOpen', '<font',$xhtml); // protect font markup in code blocks
$xhtml = str_replace('ckgeditFONTClose', 'font>',$xhtml);
$xhtml = str_replace('DBLBACKSPLASH', '\\ ',$xhtml);
$xhtml = str_replace('NWPIPECHARACTER', '|',$xhtml);
$xhtml = str_replace('<blockquote>','',$xhtml);
$xhtml = str_replace('</blockquote>','
',$xhtml);
$xhtml= preg_replace_callback(
'/(\s*)?
(.*?)<\/blockquote>(\s*<\/p>)?/ms',
function($matches) {
$matches[0] = preg_replace("/()?\s*(
)\s*(<\/p>)?/m","$2",$matches[0]);
$matches[0] = preg_replace("/()?\s*(<\/blockquote>)\s*(<\/p>)?/m","$2
",$matches[0]);
// $matches[0] = str_replace('', '', $matches[0]);
return $matches[0];
}, $xhtml
);
$ua = strtolower ($_SERVER['HTTP_USER_AGENT']);
if(strpos($ua,'chrome') !== false) {
$xhtml = preg_replace_callback(
'/(?<=)/sm',
function($matches) {
$ret_str = " " . trim($matches[3]) . " " . trim($matches[2]) . " " . trim($matches[1]) ;
return $ret_str;
},
$xhtml
);
}
return $xhtml;
}
function write_debug($what,$line="") {
return;
$handle = fopen("ckgedit_php.txt", "a");
// if(is_array($what)) $what = print_r($what,true);
if($line) $what = "line $line\n" . $what;
fwrite($handle,"$what\n");
fclose($handle);
}
function get_switch_fb_value() {
if ($this->getUserFb() == 'dokuwiki') {
$fbText = $this->getLang('btn_val_ckg_fb');
} else {
$fbText = $this->getLang('btn_val_dw_fb');
}
return $fbText;
}
function get_switch_fb_title() {
if ($this->getUserFb() == 'dokuwiki') {
$fbText = $this->getLang('btn_title_ckg_fb');
} else {
$fbText = $this->getLang('btn_title_dw_fb');
}
return $fbText;
}
function getUserFb() {
//get user file browser
if (!isset($_COOKIE['ckgFbOpt'])) {
$_COOKIE['ckgFbOpt'] = $this->getConf('default_ckg_filebrowser');
}
return $_COOKIE['ckgFbOpt'];
}
} //end of action class
?>