made markdown/showdown image processing codepot wiki-aware

This commit is contained in:
hyung-hwan 2016-01-17 14:06:33 +00:00
parent 16d4213c53
commit 45d2d50ba6
5 changed files with 126 additions and 86 deletions

View File

@ -470,9 +470,6 @@ class Wiki extends Controller
function attachment0 ($projectid = '', $target = '') function attachment0 ($projectid = '', $target = '')
{ {
//$target => projectid:wikiname:attachment
//$target => projectid:#I1:file
$login = $this->login->getUser (); $login = $this->login->getUser ();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
@ -489,6 +486,8 @@ class Wiki extends Controller
$part = explode (':', $target); $part = explode (':', $target);
if (count($part) == 3) if (count($part) == 3)
{ {
//$target => projectid:wikiname:attachment
//$target => projectid:#I1:file
if ($part[0] == '') $part[0] = $projectid; if ($part[0] == '') $part[0] = $projectid;
if ($part[1][0] == '#' && $part[1][1] == 'I') if ($part[1][0] == '#' && $part[1][1] == 'I')
{ {
@ -500,6 +499,20 @@ class Wiki extends Controller
$this->_handle_wiki_attachment ($login, $part[0], $part[1], $part[2]); $this->_handle_wiki_attachment ($login, $part[0], $part[1], $part[2]);
} }
} }
else if (count($part) == 2)
{
//$target => wikiname:attachment
//$target => #I1:file
if ($part[0][0] == '#' && $part[0][1] == 'I')
{
$issueid = substr ($part[0],2);
$this->_handle_issue_file ($login, $projectid, $issueid, $part[1]);
}
else
{
$this->_handle_wiki_attachment ($login, $projectid, $part[0], $part[1]);
}
}
} }
function attachment ($projectid = '', $wikiname = '', $filename = '') function attachment ($projectid = '', $wikiname = '', $filename = '')
@ -538,6 +551,25 @@ class Wiki extends Controller
} }
if ($part[2] != '') $filename = $part[2]; if ($part[2] != '') $filename = $part[2];
} }
else if (count($part) == 2)
{
//$target => wikiname:attachment
//$target => #I1:file
if ($part[0] != '')
{
if ($part[0][0] == '#' && $part[0][1] == 'I')
{
$issueid = substr ($part[0],2);
$wikiname = '';
}
else
{
$wikiname = $part[0];
$issueid = '';
}
}
if ($part[1] != '') $filename = $part[1];
}
if ($wikiname != '') if ($wikiname != '')
$this->_handle_wiki_attachment ($login, $projectid, $wikiname, $filename); $this->_handle_wiki_attachment ($login, $projectid, $wikiname, $filename);

View File

@ -32,6 +32,10 @@ $file_count = count($wiki->attachments);
<script type="text/javascript"> <script type="text/javascript">
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
var previewing_text = false;
function show_alert (outputMsg, titleMsg) function show_alert (outputMsg, titleMsg)
{ {
$('#wiki_edit_alert').html(outputMsg).dialog({ $('#wiki_edit_alert').html(outputMsg).dialog({
@ -48,8 +52,33 @@ function show_alert (outputMsg, titleMsg)
}); });
} }
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
var previewing_text = false; buttons: {
"OK": function () {
// do nothing, don't event close the dialog.
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function resize_text_editor() function resize_text_editor()
{ {
@ -76,7 +105,6 @@ function resize_text_editor()
} }
} }
function preview_text (input_text) function preview_text (input_text)
{ {
if (previewing_text) if (previewing_text)
@ -107,7 +135,7 @@ function preview_text (input_text)
input_text, input_text,
"wiki_edit_text_preview", "wiki_edit_text_preview",
"<?php print site_url()?>/wiki/show/<?php print $project->id?>/", "<?php print site_url()?>/wiki/show/<?php print $project->id?>/",
"<?php print site_url()?>/wiki/attachment0/<?php print $project->id?>/", "<?php print site_url()?>/wiki/attachment/<?php print $project->id?>/" + codepot_string_to_hex(wiki_original_name) + "/",
true // raw true // raw
); );
} }
@ -117,7 +145,7 @@ function preview_text (input_text)
input_text, input_text,
"wiki_edit_text_preview", "wiki_edit_text_preview",
"<?php print site_url()?>/wiki/show/<?php print $project->id?>/", "<?php print site_url()?>/wiki/show/<?php print $project->id?>/",
"<?php print site_url()?>/wiki/attachment0/<?php print $project->id?>/", "<?php print site_url()?>/wiki/attachment/<?php print $project->id?>/" + codepot_string_to_hex(wiki_original_name) + "/",
true // raw true // raw
); );
} }
@ -204,7 +232,6 @@ function kill_file (no)
resize_text_editor (); resize_text_editor ();
} }
function update_original_file_name_array () function update_original_file_name_array ()
{ {
$('#wiki_edit_add_file_list').empty(); $('#wiki_edit_add_file_list').empty();
@ -259,37 +286,6 @@ function update_original_file_name_array ()
var wiki_text_editor = null; var wiki_text_editor = null;
var work_in_progress = false; var work_in_progress = false;
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
buttons: {
"OK": function () {
// do nothing
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function save_wiki (wiki_new_name, wiki_new_text) function save_wiki (wiki_new_name, wiki_new_text)
{ {

View File

@ -37,6 +37,8 @@ $file_count = count($wiki->attachments);
?> ?>
<script type="text/javascript"> <script type="text/javascript">
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
function show_alert (outputMsg, titleMsg) function show_alert (outputMsg, titleMsg)
{ {
@ -54,6 +56,34 @@ function show_alert (outputMsg, titleMsg)
}); });
} }
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
buttons: {
"OK": function () {
// do nothing, don't event close the dialog.
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function resize_editor() function resize_editor()
{ {
var editor = $("#wiki_edit_text_editor"); var editor = $("#wiki_edit_text_editor");
@ -208,36 +238,6 @@ function update_original_file_name_array ()
var wiki_text_editor = null; var wiki_text_editor = null;
var work_in_progress = false; var work_in_progress = false;
var wiki_original_name = '<?php print addslashes($wiki->name); ?>';
var wiki_original_text = <?php print codepot_json_encode($wiki->text); ?>;
function show_in_progress_message (outputMsg, titleMsg)
{
if (titleMsg == null || outputMsg == null)
{
$('#wiki_edit_alert').dialog('close');
}
else
{
$('#wiki_edit_alert').html(outputMsg).dialog({
title: titleMsg,
resizable: false,
modal: true,
width: 'auto',
height: 'auto',
buttons: {
"OK": function () {
// do nothing
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !work_in_progress;
}
});
}
}
function save_wiki (wiki_new_name, wiki_new_text) function save_wiki (wiki_new_name, wiki_new_text)
{ {

View File

@ -423,8 +423,7 @@ var Url = {
{ {
var tmp = r[1].replace(/~(.)/g, '$1'); var tmp = r[1].replace(/~(.)/g, '$1');
tmp = Url.encode (tmp); tmp = Url.encode (tmp);
img.src = options && options.imgFormat? img.src = options && options.imgFormat? formatLink (tmp, options.imgFormat): tmp;
formatLink (tmp, options.imgFormat): tmp;
} }
img.alt = r[2] === undefined img.alt = r[2] === undefined

View File

@ -1125,8 +1125,6 @@ showdown.subParser('anchors', function (text, options, globals) {
} }
} }
url = showdown.helper.escapeCharacters(url, '*_', false);
// codepot // codepot
var front2 = url.substr(0, 2); var front2 = url.substr(0, 2);
var front3 = url.substr(0, 3); var front3 = url.substr(0, 3);
@ -1140,6 +1138,8 @@ showdown.subParser('anchors', function (text, options, globals) {
url = options.codepotLinkBase + codepot_string_to_hex(url); url = options.codepotLinkBase + codepot_string_to_hex(url);
} }
// end codepot // end codepot
url = showdown.helper.escapeCharacters(url, '*_', false);
var result = '<a href="' + url + '"'; var result = '<a href="' + url + '"';
if (title !== '' && title !== null) { if (title !== '' && title !== null) {
@ -1909,6 +1909,19 @@ showdown.subParser('images', function (text, options, globals) {
altText = altText.replace(/"/g, '&quot;'); altText = altText.replace(/"/g, '&quot;');
altText = showdown.helper.escapeCharacters(altText, '*_', false); altText = showdown.helper.escapeCharacters(altText, '*_', false);
// codepot
if (url.match (/^[a-zA-Z]+:\/\//))
{
// begins with XXX://
// do nothing special
}
else
{
url = options.codepotImageBase + codepot_string_to_hex(url);
}
// end codepot
url = showdown.helper.escapeCharacters(url, '*_', false); url = showdown.helper.escapeCharacters(url, '*_', false);
var result = '<img src="' + url + '" alt="' + altText + '"'; var result = '<img src="' + url + '" alt="' + altText + '"';
@ -2548,7 +2561,7 @@ function showdown_render_wiki_with_input_text (input_text, outputid, linkbase, i
tasklists: true, tasklists: true,
codepotLinkBase: linkbase, codepotLinkBase: linkbase,
codepotImgBase: imgbase codepotImageBase: imgbase
}); });
function decodeEntities(str) function decodeEntities(str)