*/
class action_plugin_ckgdoku_edit extends DokuWiki_Action_Plugin {
var $fck_location = "ckeditor";
var $helper = false;
var $ckgdoku_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', 'ckgdoku');
if(!plugin_isdisabled('captcha')) {
$this->captcha = plugin_load('helper', 'captcha');
If(!$this->captcha) $this->captcha = false;
}
else $this->captcha = false;
}
function register(Doku_Event_Handler $controller)
{
$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);
if(preg_match("/$ns/",$_REQUEST['id']) || 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, 'ckgdoku_edit');
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'ckgdoku_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+_ckgdoku_NPBBR_\s+<\/p>/ms',"\n",$xhtml);
$xhtml = str_replace('_ckgdoku_NPBBR_', " ", $xhtml);
$xhtml = str_replace('_ckgdoku_QUOT_', '"', $xhtml);
$xhtml = str_replace('_ckgdoku_NL', "\n", $xhtml);
$xhtml = str_replace(' |
/ms", "TPRE_CODE", $matches[2]);
$matches[2] = preg_replace("/
',"",$matches[2]);
return $matches[1] . $matches[2] . "
";
},
$this->xhtml
);
if($pos !== false) {
$this->xhtml = preg_replace_callback(
'/(TPRE_CODE|TPRE_FILE)(.*?)(TPRE_CLOSE)/ms',
create_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',
create_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',
create_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',
create_function(
'$matches',
'return str_replace("<", "< ",$matches[0]);'
),
$this->xhtml
);
if($this->draft_started) return $this->xhtml;
$cname = getCacheName($INFO['client'].$ID,'.draft.fckl');
$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($draft_started) return $this->xhtml;
return true;
}
/**
* function dw_edit_displayed
* @author Myron Turner
* determines whether or not to show or hide the
* 'DW Edit' button
*/
function dw_edit_displayed()
{
global $INFO;
$dw_edit_display = @$this->getConf('dw_edit_display');
if(!isset($dw_edit_display))return ""; //version 0.
if($dw_edit_display != 'all') {
$admin_exclusion = false;
if($dw_edit_display == 'admin' && ($INFO['isadmin'] || $INFO['ismanager']) ) {
$admin_exclusion = true;
}
if($dw_edit_display == 'none' || $admin_exclusion === false) {
return ' style = "display:none"; ';
}
return "";
}
return "";
}
/**
* function _print
* @author Myron Turner
*/
function _print()
{
global $INFO;
global $lang;
global $ckgdoku_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_url= rtrim(DOKU_URL,'/');
$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_url/lib/exe/mediamanager.php?ns=$ns&edid=wiki__text&onselect=ckg_edit_mediaman_insert&ckg_media=img\",
filebrowserBrowseUrl: \"$doku_url/lib/exe/mediamanager.php?ns=$ns&edid=wiki__text&onselect=ckg_edit_mediaman_insertlink&ckg_media=link\"";
} else {
$fbOptions = "filebrowserImageBrowseUrl : \"$doku_url/lib/plugins/ckgdoku/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=$doku_url/lib/plugins/ckgdoku/fckeditor/editor/filemanager/connectors/php/connector.php\",
filebrowserBrowseUrl: \"$doku_url/lib/plugins/ckgdoku/fckeditor/editor/filemanager/browser/default/browser.html?Type=File&Connector=$doku_url/lib/plugins/ckgdoku/fckeditor/editor/filemanager/connectors/php/connector.php\"";
}
$ckeditor_replace =<<
', "\n\n|
",$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 _ckgdoku_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('ckgdokuFONTOpen', '<font',$xhtml); // protect font markup in code blocks $xhtml = str_replace('ckgdokuFONTClose', 'font>',$xhtml); $xhtml = str_replace('DBLBACKSPLASH', '\\ ',$xhtml); $xhtml = str_replace('NWPIPECHARACTER', '|',$xhtml); $ua = strtolower ($_SERVER['HTTP_USER_AGENT']); if(strpos($ua,'chrome') !== false) { $xhtml = preg_replace_callback( '/(?<=)/sm', create_function( '$matches', '$ret_str = " " . trim($matches[3]) . " " . trim($matches[2]) . " " . trim($matches[1]) ; return $ret_str;' ), $xhtml ); } return $xhtml; } function write_debug($what) { return; $handle = fopen("ckgdoku_php.txt", "a"); // if(is_array($what)) $what = print_r($what,true); 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 ?>