Skip to content

Commit

Permalink
replaced refresh_save.php with AJAX_CALL_UNKNOWN in meta.php
Browse files Browse the repository at this point in the history
  • Loading branch information
turnermm committed Dec 3, 2015
1 parent 43c39c8 commit deb291d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 32 deletions.
102 changes: 96 additions & 6 deletions action/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
define('FCK_ACTION_SUBDIR', DOKU_PLUGIN . 'ckgedit/action/');
require_once(DOKU_PLUGIN.'action.php');

class action_plugin_ckgedit_meta extends DokuWiki_Action_Plugin {
Expand All @@ -13,7 +14,7 @@ class action_plugin_ckgedit_meta extends DokuWiki_Action_Plugin {
var $user_rewrite = false;
var $helper;
var $dokuwiki_priority;

var $wiki_text;
function __construct() {
$this->helper = plugin_load('helper', 'ckgedit');
$this->dokuwiki_priority = $this->getConf('dw_priority');
Expand All @@ -31,10 +32,100 @@ function register(Doku_Event_Handler $controller) {
$controller->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', $this, 'setupDWEdit');
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'reset_user_rewrite_check');
$controller->register_hook('DOKUWIKI_DONE', 'BEFORE', $this, 'restore_conf');

$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this,'_ajax_call');
}


function _ajax_call(Doku_Event $event, $param) {

if ($event->data !== 'refresh_save') {
return;
}

$event->stopPropagation();
$event->preventDefault();
global $INPUT;


$rsave_id = urldecode($INPUT->str('rsave_id'));
$path = pathinfo($rsave_id);
if($path['extension'] != 'ckgedit') {
echo "failed";
return;
}

$this->wiki_text = urldecode($INPUT->str('wikitext'));

if(!preg_match('/^\s+(\-|\*)/',$this->wiki_text)){
$this->wiki_text = trim($this->wiki_text);
}

/* preserve newlines in code blocks */
$this->wiki_text = preg_replace_callback(
'/(<code>|<file>)(.*?)(<\/code>|<\/file>)/ms',
create_function(
'$matches',
'return str_replace("\n", "__code_NL__",$matches[0]);'
),
$this->wiki_text
);

$this->wiki_text = preg_replace('/^\s*[\r\n]$/ms',"__n__", $this->wiki_text);
$this->wiki_text = preg_replace('/\r/ms',"", $this->wiki_text);
$this->wiki_text = preg_replace('/^\s+(?=\^|\|)/ms',"", $this->wiki_text);
$this->wiki_text = preg_replace('/__n__/',"\n", $this->wiki_text);
$this->wiki_text = str_replace("__code_NL__","\n", $this->wiki_text);


$this->wiki_text .= "\n";


$pos = strpos($this->wiki_text, 'MULTI_PLUGIN_OPEN');
if($pos !== false) {
$this->wiki_text = preg_replace_callback(
'|MULTI_PLUGIN_OPEN.*?MULTI_PLUGIN_CLOSE|ms',
create_function(
'$matches',
'return preg_replace("/\\\\\\\\/ms","\n",$matches[0]);'
),
$this->wiki_text
);

$this->wiki_text = preg_replace_callback(
'|MULTI_PLUGIN_OPEN.*?MULTI_PLUGIN_CLOSE|ms',
create_function(
'$matches',
'return preg_replace("/^\s+/ms","",$matches[0]);'
),
$this->wiki_text
);

}

$this->replace_entities();
$this->wiki_text = preg_replace('/\<\?php/i', '&lt;?php',$this->wiki_text) ;
$this->wiki_text = preg_replace('/\?>/i', '?&gt;',$this->wiki_text) ;
file_put_contents($rsave_id, $this->wiki_text);
echo 'done';

}

function replace_entities() {
global $ents;
$serialized = FCK_ACTION_SUBDIR . 'ent.ser';
$ents = unserialize(file_get_contents($serialized));

$this->wiki_text = preg_replace_callback(
'|(&(\w+);)|',
create_function(
'$matches',
'global $ents; return $ents[$matches[2]];'
),
$this->wiki_text
);

}

function insertFormElement(&$event, $param) {
global $FCKG_show_preview;

Expand Down Expand Up @@ -112,7 +203,7 @@ function preprocess(&$event, $param) {
return;
}
global $INFO, $ckgedit_lang;
$cname = $INFO['draft'];

$discard = $this->getLang('discard_edits');
$dokuwiki_priority =$this->dokuwiki_priority;
echo "<script type='text/javascript'>\n//<![CDATA[ \n";
Expand All @@ -123,10 +214,9 @@ function preprocess(&$event, $param) {
//<![CDATA[
var ckgedit_dwedit_reject = false;
function setDWEditCookie(which, e) {
var cname = "$cname";
var dom = document.getElementById('ckgedit_mode_type');
if(which == 1) {
dwedit_draft_delete("$cname");
if(which == 1) {
if(useDW_Editor) {
document.cookie = 'FCKG_USE=other;expires=';
Expand Down
8 changes: 5 additions & 3 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,15 @@ function renewLock(bak) {
if(($editor_backup) == 0 ) {
return;
}
var params = "rsave_id=" + encodeURIComponent("$meta_fn");
params += '&wikitext='+encodeURIComponent(dwform.elements.fck_wikitext.value);
params += '&call=refresh_save';
jQuery.post(
DOKU_BASE + 'lib/plugins/ckgedit/scripts/refresh_save.php',
// DOKU_BASE + 'lib/plugins/ckgedit/scripts/refresh_save.php',
DOKU_BASE + 'lib/exe/ajax.php',
params,
function (data) {
function (data) {
if(data == 'done') {
show_backup_msg("$meta_id");
}
Expand Down
25 changes: 5 additions & 20 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,14 @@ function show_backup_msg(msg) {
return false;
}

// legacy function
function remove_draft(){
// legacy functions
function remove_draft(){
}

function dwedit_draft_delete(cname) {
var debug = false;
var params = "draft_id=" +cname;
jQuery.ajax({
url: DOKU_BASE + 'lib/plugins/ckgedit/scripts/prev_delete.php',
async: false,
data: params,
type: 'POST',
dataType: 'html',
success: function(data){
if(debug) {
alert(data);
}

}
});

function dwedit_draft_delete() {
}

// legacy functions end

function setEdHeight(h) {
h = parseInt(h);
document.cookie = 'ckgEdht=' + h +';expires="";path=' +JSINFO['doku_base'];
Expand Down
6 changes: 4 additions & 2 deletions scripts/refresh_save.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

$rsave_id = urldecode($INPUT->str('rsave_id'));
$path = pathinfo($rsave_id);
if($path['extension'] != 'ckgedit') exit('1');
if($path['extension'] != 'ckgedit') exit('1');
if(!preg_match("#\/meta\/#", $path['dirname'])) exit(1);
$wiki_text = urldecode($INPUT->str('wikitext'));

if(!preg_match('/^\s+(\-|\*)/',$wiki_text)){
Expand Down Expand Up @@ -58,7 +59,8 @@
}

replace_entities();
$wiki_text = preg_replace('/\s*\<\?php/i', '&lt;?php',$wiki_text) ;
$wiki_text = preg_replace('/\<\?php/i', '&lt;?php',$wiki_text) ;
$wiki_text = preg_replace('/\?>/i', '?&gt;',$wiki_text) ;
file_put_contents($rsave_id, $wiki_text);
echo 'done';

Expand Down
2 changes: 1 addition & 1 deletion scripts/script-cmpr.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit deb291d

Please sign in to comment.