From 986812edd5dd388e0509bae3f5f4b339e3cd5f0f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 28 Aug 2015 02:01:16 +0000 Subject: [PATCH] enhanced the code folder view to allow renaming --- codepot/src/codepot/controllers/code.php | 76 +++++++- .../codepot/language/english/code_lang.php | 1 + .../codepot/language/english/common_lang.php | 1 + .../language/indonesian/common_lang.php | 1 + .../src/codepot/language/korean/code_lang.php | 2 +- .../codepot/language/korean/common_lang.php | 1 + .../src/codepot/models/subversionmodel.php | 131 ++++++++++---- codepot/src/codepot/views/code_folder.php | 167 ++++++++++++++++-- codepot/src/js/codepot.js | 20 +++ 9 files changed, 343 insertions(+), 57 deletions(-) diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index 2fa46fdc..4ced7a81 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -107,7 +107,7 @@ class Code extends Controller if (count($import_files) > 0 && $this->subversion->importFiles ($projectid, $path, $login['id'], $post_new_message, $import_files, $this->upload) === FALSE) { - $popup_error_message = $this->subversion->import_files_errmsg; + $popup_error_message = $this->subversion->getErrorMessage(); } else { @@ -450,7 +450,7 @@ class Code extends Controller if (count($import_files) > 0 && $this->subversion->importFiles ($projectid, $path, $login['id'], $post_new_message, $import_files, $this->upload) === FALSE) { - $status = 'repoerr - ' . $this->subversion->import_files_errmsg; + $status = 'repoerr - ' . $this->subversion->getErrorMessage(); } else { @@ -471,8 +471,7 @@ class Code extends Controller { $this->load->model ('ProjectModel', 'projects'); $this->load->model ('SubversionModel', 'subversion'); - $this->load->library ('upload'); - + $login = $this->login->getUser (); $revision_saved = -1; @@ -512,9 +511,72 @@ class Code extends Controller } } - if (count($delete_files) > 0 && $this->subversion->deleteFiles ($projectid, $path, $login['id'], $post_delete_message, $delete_files, $this->upload) === FALSE) + if (count($delete_files) > 0 && $this->subversion->deleteFiles ($projectid, $path, $login['id'], $post_delete_message, $delete_files) === FALSE) { - $status = 'repoerr - ' . $this->subversion->delete_files_errmsg; + $status = 'repoerr - ' . $this->subversion->getErrorMessage(); + } + else + { + $status = 'ok'; + } + } + else + { + $status = 'posterr - invalid post data'; + } + } + } + + print $status; + } + + function xhr_rename ($projectid = '', $path = '') + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('SubversionModel', 'subversion'); + + $login = $this->login->getUser (); + $revision_saved = -1; + + if ($login['id'] == '') + { + $status = 'signin'; + } + else + { + $path = $this->converter->HexToAscii ($path); + if ($path == '.') $path = ''; /* treat a period specially */ + $path = $this->_normalize_path ($path); + + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $status = "dberr - failed to get the project {$projectid}"; + } + else if ($project === NULL) + { + $status = "noent - no such project {$projectid}"; + } + else + { + $post_rename_message = $this->input->post('code_rename_message'); + $post_rename_file_count = $this->input->post('code_rename_file_count'); + if ($post_rename_message !== FALSE && $post_rename_file_count !== FALSE) + { + $rename_files = array (); + for ($i = 0; $i < $post_rename_file_count; $i++) + { + $d1 = $this->input->post("code_rename_file_old_$i"); + $d2 = $this->input->post("code_rename_file_new_$i"); + if (strlen($d1) > 0 && strlen($d2) > 0) + { + array_push ($rename_files, array($d1, $d2)); + } + } + + if (count($rename_files) > 0 && $this->subversion->renameFiles ($projectid, $path, $login['id'], $post_rename_message, $rename_files) === FALSE) + { + $status = 'repoerr - ' . $this->subversion->getErrorMessage(); } else { @@ -570,7 +632,7 @@ class Code extends Controller { if ($this->subversion->storeFile ($projectid, $path, $login['id'], $message, $text) === FALSE) { - $status = 'repoerr - ' . $this->subversion->store_file_errmsg; + $status = 'repoerr - ' . $this->subversion->getErrorMessage(); } else { diff --git a/codepot/src/codepot/language/english/code_lang.php b/codepot/src/codepot/language/english/code_lang.php index fa25ecd9..3b9ebb58 100644 --- a/codepot/src/codepot/language/english/code_lang.php +++ b/codepot/src/codepot/language/english/code_lang.php @@ -16,4 +16,5 @@ $lang['CODE_SEARCH_IS_REGEX'] = 'Search string is a regular expression'; $lang['CODE_SEARCH_WILDCARD'] = 'Enter a wildcard pattern'; $lang['CODE_FMT_DELETE_X_SELECTED_FILES'] = 'Delete %d selected file(s)'; +$lang['CODE_FMT_RENAME_X_SELECTED_FILES'] = 'Rename %d selected file(s)'; ?> diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index 430b4541..6bcc4b75 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -83,6 +83,7 @@ $lang['Projects'] = 'Projects'; $lang['Public'] = 'Public'; $lang['Purge'] = 'Purge'; $lang['Recently resolved issues'] = 'Recently resolved issues'; +$lang['Rename'] = 'Rename'; $lang['Repository'] = 'Repository'; $lang['Return'] = 'Return'; $lang['Revision'] = 'Revision'; diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index 676bf5c9..6910ad6e 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -83,6 +83,7 @@ $lang['Projects'] = 'Proyek'; $lang['Public'] = 'Public'; $lang['Purge'] = 'Purge'; $lang['Recently resolved issues'] = 'Recently resolved issues'; +$lang['Rename'] = 'Rename'; $lang['Return'] = 'Return'; $lang['Repository'] = 'Repository'; $lang['Revision'] = 'Revisi'; diff --git a/codepot/src/codepot/language/korean/code_lang.php b/codepot/src/codepot/language/korean/code_lang.php index 7644dded..58cb8597 100644 --- a/codepot/src/codepot/language/korean/code_lang.php +++ b/codepot/src/codepot/language/korean/code_lang.php @@ -16,5 +16,5 @@ $lang['CODE_SEARCH_IS_REGEX'] = '검색어가 정규식입니다'; $lang['CODE_SEARCH_WILDCARD'] = '와일드카드 패턴을 입력하세요'; $lang['CODE_FMT_DELETE_X_SELECTED_FILES'] = '선택된 파일 %d개를 삭제합니다'; - +$lang['CODE_FMT_RENAME_X_SELECTED_FILES'] = '선택된 파일 %d개의 이름변경'; ?> diff --git a/codepot/src/codepot/language/korean/common_lang.php b/codepot/src/codepot/language/korean/common_lang.php index 7a489730..fa4140c7 100644 --- a/codepot/src/codepot/language/korean/common_lang.php +++ b/codepot/src/codepot/language/korean/common_lang.php @@ -83,6 +83,7 @@ $lang['Projects'] = '프로젝트'; $lang['Public'] = '공개'; $lang['Purge'] = '정화하기'; $lang['Recently resolved issues'] = '최근해결이슈'; +$lang['Rename'] = '이름변경'; $lang['Return'] = '복귀'; $lang['Repository'] = '저장소'; $lang['Revision'] = '리비전'; diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index ffc9dcdd..ab26a37b 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -2,6 +2,18 @@ class SubversionModel extends Model { + protected $errmsg = ''; + + function capture_error ($errno, $errmsg) + { + $this->errmsg = $errmsg; + } + + function getErrorMessage () + { + return $this->errmsg; + } + function SubversionModel () { parent::Model (); @@ -249,28 +261,10 @@ class SubversionModel extends Model return $fileinfo; } - public $store_file_errmsg = ''; - public $import_files_errmsg = ''; - public $delete_files_errmsg = ''; - - function capture_save_error ($errno, $errmsg) - { - $this->store_file_errmsg = $errmsg; - } - - function capture_import_error ($errno, $errmsg) - { - $this->import_files_errmsg = $errmsg; - } - - function capture_delete_error ($errno, $errmsg) - { - $this->delete_files_errmsg = $errmsg; - } function storeFile ($projectid, $path, $committer, $commit_message, $text) { - $store_file_errmsg = ''; + $errmsg = ''; //$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; $canon_path = $this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"); @@ -278,7 +272,7 @@ class SubversionModel extends Model $file_name = basename($canon_path); $dirurl = 'file://' . $canon_dir; - set_error_handler (array ($this, 'capture_save_error')); + set_error_handler (array ($this, 'capture_error')); $tfname = @tempnam(__FILE__, 'codepot-store-file-'); restore_error_handler (); if ($tfname === FALSE) @@ -290,7 +284,7 @@ class SubversionModel extends Model codepot_delete_files ($actual_tfname, TRUE); // delete the directory in case it exists /* TODO: optimize it not to get all files... svn_checkout needs to be enhanced???*/ - set_error_handler (array ($this, 'capture_save_error')); + set_error_handler (array ($this, 'capture_error')); if (@svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $committer) === FALSE || @svn_checkout ($dirurl, $actual_tfname, SVN_REVISION_HEAD, SVN_NON_RECURSIVE) === FALSE || @file_put_contents ("{$actual_tfname}/{$file_name}", $text) === FALSE || @@ -310,7 +304,7 @@ class SubversionModel extends Model function importFiles ($projectid, $path, $committer, $commit_message, $files, $uploader) { - $this->import_files_errmsg = ''; + $this->errmsg = ''; //$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; $full_path = CODEPOT_SVNREPO_DIR."/{$projectid}"; @@ -318,7 +312,7 @@ class SubversionModel extends Model $canon_path = $this->_canonical_path($full_path); $dirurl = 'file://' . $canon_path; - set_error_handler (array ($this, 'capture_import_error')); + set_error_handler (array ($this, 'capture_error')); $tfname = @tempnam(__FILE__, 'codepot-import-files-'); restore_error_handler (); if ($tfname === FALSE) @@ -329,10 +323,9 @@ class SubversionModel extends Model $actual_tfname = $tfname . '.d'; codepot_delete_files ($actual_tfname, TRUE); // delete the directory in case it exists - mkdir ($actual_tfname); - - set_error_handler (array ($this, 'capture_import_error')); - if (@svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $committer) === FALSE || + set_error_handler (array ($this, 'capture_error')); + if (@mkdir ($actual_tfname) === FALSE || + @svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $committer) === FALSE || @svn_checkout ($dirurl, $actual_tfname, SVN_REVISION_HEAD, 0) === FALSE) { restore_error_handler (); @@ -455,9 +448,9 @@ class SubversionModel extends Model return TRUE; } - function deleteFiles ($projectid, $path, $committer, $commit_message, $files, $uploader) + function deleteFiles ($projectid, $path, $committer, $commit_message, $files) { - $this->delete_files_errmsg = ''; + $this->errmsg = ''; //$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; $full_path = CODEPOT_SVNREPO_DIR."/{$projectid}"; @@ -465,7 +458,7 @@ class SubversionModel extends Model $canon_path = $this->_canonical_path($full_path); $dirurl = 'file://' . $canon_path; - set_error_handler (array ($this, 'capture_delete_error')); + set_error_handler (array ($this, 'capture_error')); $tfname = @tempnam(__FILE__, 'codepot-delete-files-'); restore_error_handler (); if ($tfname === FALSE) @@ -476,10 +469,9 @@ class SubversionModel extends Model $actual_tfname = $tfname . '.d'; codepot_delete_files ($actual_tfname, TRUE); // delete the directory in case it exists - mkdir ($actual_tfname); - - set_error_handler (array ($this, 'capture_delete_error')); - if (@svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $committer) === FALSE || + set_error_handler (array ($this, 'capture_error')); + if (@mkdir ($actual_tfname) === FALSE || + @svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $committer) === FALSE || @svn_checkout ($dirurl, $actual_tfname, SVN_REVISION_HEAD, 0) === FALSE) { restore_error_handler (); @@ -515,6 +507,77 @@ class SubversionModel extends Model return TRUE; } + function renameFiles ($projectid, $path, $committer, $commit_message, $files) + { + $this->errmsg = ''; + + //$url = 'file://'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; + $full_path = CODEPOT_SVNREPO_DIR."/{$projectid}"; + if (strlen($path) > 0) $full_path .= "/{$path}"; + $canon_path = $this->_canonical_path($full_path); + $dirurl = 'file://' . $canon_path; + + set_error_handler (array ($this, 'capture_error')); + $tfname = @tempnam(__FILE__, 'codepot-rename-files-'); + restore_error_handler (); + if ($tfname === FALSE) + { + return FALSE; + } + + $actual_tfname = $tfname . '.d'; + codepot_delete_files ($actual_tfname, TRUE); // delete the directory in case it exists + + set_error_handler (array ($this, 'capture_error')); + if (@mkdir ($actual_tfname) === FALSE || + @svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $committer) === FALSE || + @svn_checkout ($dirurl, $actual_tfname, SVN_REVISION_HEAD, 0) === FALSE) + { + restore_error_handler (); + codepot_delete_files ($actual_tfname, TRUE); + @unlink ($tfname); + return FALSE; + } + + foreach ($files as $f) + { + $xname = $actual_tfname . '/' . $f[0]; + $yname = $actual_tfname . '/' . $f[1]; + + if ($f[0] == $f[1]) continue; + + if (@file_exists($yname)) + { + $this->errmsg = "{$f[1]} already exists"; + restore_error_handler (); + codepot_delete_files ($actual_tfname, TRUE); + @unlink ($tfname); + return FALSE; + } + + if (@svn_move ($xname, $yname, TRUE) === FALSE) + { + restore_error_handler (); + codepot_delete_files ($actual_tfname, TRUE); + @unlink ($tfname); + return FALSE; + } + } + + if (($result = @svn_commit ($commit_message, $actual_tfname)) === FALSE) + { + restore_error_handler (); + codepot_delete_files ($actual_tfname, TRUE); + @unlink ($tfname); + return FALSE; + } + + restore_error_handler (); + codepot_delete_files ($actual_tfname, TRUE); // delete the directory in case it exists + @unlink ($tfname); + return TRUE; + } + function getRevHistory ($projectid, $path, $rev) { //$url = 'file:///'.CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"; diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index 615875de..6de4ff5d 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -201,6 +201,8 @@ function render_readme() var new_item_no = 0; var import_in_progress = false; var delete_in_progress = false; +var rename_in_progress = false; +var rename_last_input = {}; function get_new_item_html(no, type, name) { @@ -212,9 +214,9 @@ $(function () { new_item_no = 0; - $('#code_folder_mainarea_new_file_form_item_list').append (get_new_item_html(new_item_no, 'file', 'file')); - $('#code_folder_mainarea_new_dir_form_item_list').append (get_new_item_html(new_item_no, 'text', 'dir')); - $('#code_folder_mainarea_new_empfile_form_item_list').append (get_new_item_html(new_item_no, 'text', 'empfile')); + $('#code_folder_mainarea_new_file_list').append (get_new_item_html(new_item_no, 'file', 'file')); + $('#code_folder_mainarea_new_dir_list').append (get_new_item_html(new_item_no, 'text', 'dir')); + $('#code_folder_mainarea_new_empfile_list').append (get_new_item_html(new_item_no, 'text', 'empfile')); $("#code_folder_mainarea_new_form_tabs").tabs (); @@ -231,9 +233,9 @@ $(function () { if (import_in_progress) return; ++new_item_no; - $('#code_folder_mainarea_new_file_form_item_list').append (get_new_item_html(new_item_no, 'file', 'file')); - $('#code_folder_mainarea_new_dir_form_item_list').append (get_new_item_html(new_item_no, 'text', 'dir')); - $('#code_folder_mainarea_new_empfile_form_item_list').append (get_new_item_html(new_item_no, 'text', 'empfile')); + $('#code_folder_mainarea_new_file_list').append (get_new_item_html(new_item_no, 'file', 'file')); + $('#code_folder_mainarea_new_dir_list').append (get_new_item_html(new_item_no, 'text', 'dir')); + $('#code_folder_mainarea_new_empfile_list').append (get_new_item_html(new_item_no, 'text', 'empfile')); }, 'lang->line('OK')?>': function () { if (import_in_progress) return; @@ -328,8 +330,6 @@ $(function () { 'lang->line('OK')?>': function () { if (delete_in_progress) return; - $('#code_folder_mainarea_new_item_count').val (new_item_no + 1); - if (!!window.FormData) { // FormData is supported @@ -339,7 +339,7 @@ $(function () { form_data.append ('code_delete_message', $('#code_folder_mainarea_delete_message').val()); var xi = 0; - for (var i = 0; i < ; i++) + for (var i = 1; i <= ; i++) { var f = $('#code_folder_mainarea_result_table_file_selector_' + i); if (f != null && f.is(':checked')) @@ -403,23 +403,152 @@ $(function () { } ); + $('#code_folder_mainarea_rename_form_div').dialog ( + { + title: 'lang->line('rename');?>', + resizable: true, + autoOpen: false, + width: 'auto', + height: 'auto', + modal: true, + buttons: { + 'lang->line('OK')?>': function () { + if (rename_in_progress) return; + + if (!!window.FormData) + { + // FormData is supported + rename_in_progress = true; + + var form_data = new FormData(); + + form_data.append ('code_rename_message', $('#code_folder_mainarea_rename_message').val()); + var xi = 0; + for (var i = 1; i <= ; i++) + { + var f = $('#code_folder_mainarea_result_table_file_selector_' + i); + if (f != null && f.is(':checked')) + { + form_data.append ('code_rename_file_old_' + xi, f.val()); + + var fx = $('#code_folder_mainarea_rename_file_' + xi); + var fxv = fx != null? fx.val(): ''; + form_data.append ('code_rename_file_new_' + xi, fxv); + + xi++; + } + } + form_data.append ('code_rename_file_count', xi); + + $('#code_folder_mainarea_rename_form_div').dialog('disable'); + $.ajax({ + url: codepot_merge_path('', 'id}/{$hex_headpath}"; ?>'), + type: 'POST', + data: form_data, + mimeType: 'multipart/form-data', + contentType: false, + processData: false, + cache: false, + + success: function (data, textStatus, jqXHR) { + rename_in_progress = false; + $('#code_folder_mainarea_rename_form_div').dialog('enable'); + $('#code_folder_mainarea_rename_form_div').dialog('close'); + if (data == 'ok') + { + // refresh the page to the head revision + $(location).attr ('href', codepot_merge_path('', 'id}/{$hex_headpath}"; ?>')); + } + else + { + show_alert ('
' + codepot_htmlspecialchars(data) + '
', "lang->line('Error')?>"); + } + }, + + error: function (jqXHR, textStatus, errorThrown) { + rename_in_progress = false; + $('#code_folder_mainarea_rename_form_div').dialog('enable'); + $('#code_folder_mainarea_rename_form_div').dialog('close'); + show_alert ('Failed - ' + errorThrown, "lang->line('Error')?>"); + } + }); + } + else + { + show_alert ('
NOT SUPPORTED
', "lang->line('Error')?>"); + } + + }, + 'lang->line('Cancel')?>': function () { + if (rename_in_progress) return; + $('#code_folder_mainarea_rename_form_div').dialog('close'); + } + + }, + + beforeClose: function() { + // if importing is in progress, prevent dialog closing + rename_last_input = {}; + var xi = 0; + for (var i = 1; i <= ; i++) + { + var f = $('#code_folder_mainarea_result_table_file_selector_' + i); + if (f != null && f.is(':checked')) + { + var fx = $('#code_folder_mainarea_rename_file_' + xi); + var fxv = fx != null? fx.val(): ''; + rename_last_input[f.val()] = fxv; + + xi++; + } + } + + return !rename_in_progress; + } + } + ); + $('#code_folder_mainarea_new_button').button().click (function() { $('#code_folder_mainarea_new_form_div').dialog('open'); }); $('#code_folder_mainarea_delete_button').button().click (function() { var xi = 0; - for (var i = 0; i < ; i++) + for (var i = 1; i <= ; i++) { var f = $('#code_folder_mainarea_result_table_file_selector_' + i); if (f != null && f.is(':checked')) xi++; } - $('#code_folder_mainarea_delete_display_message').text ( + $('#code_folder_mainarea_delete_form_div').dialog ('option', 'title', codepot_sprintf ("lang->line('CODE_FMT_DELETE_X_SELECTED_FILES')) ?>", xi) ); $('#code_folder_mainarea_delete_form_div').dialog('open'); }); + $('#code_folder_mainarea_rename_button').button().click (function() { + var xi = 0; + + $('#code_folder_mainarea_rename_file_table').empty(); + for (var i = 1; i <= ; i++) + { + var f = $('#code_folder_mainarea_result_table_file_selector_' + i); + if (f != null && f.is(':checked')) + { + var li = rename_last_input[f.val()]; + if (li == null) li = ''; + $('#code_folder_mainarea_rename_file_table').append ( + codepot_sprintf ('%s', + codepot_htmlspecialchars(f.val()), xi, codepot_addslashes(li)) + ); + xi++; + } + } + + $('#code_folder_mainarea_rename_form_div').dialog ('option', 'title', + codepot_sprintf ("lang->line('CODE_FMT_RENAME_X_SELECTED_FILES')) ?>", xi) + ); + $('#code_folder_mainarea_rename_form_div').dialog('open'); + }); 0): ?> @@ -699,6 +828,7 @@ $this->load->view ( { printf ('%s', $this->lang->line('New')); printf ('%s', $this->lang->line('Delete')); + printf ('%s', $this->lang->line('Rename')); } if ($file_count > 0) @@ -965,13 +1095,13 @@ $this->load->view (
lang->line('Unzip a zip file'); ?>
-
    +
      -
        +
          -
            +
              @@ -979,11 +1109,18 @@ $this->load->view (
              -

               
              lang->line('Message'); ?>:
              +
              +
              lang->line('Message'); ?>:
              +
              +
              +
              +
              +
              +
              diff --git a/codepot/src/js/codepot.js b/codepot/src/js/codepot.js index 78d00e77..444af8a6 100644 --- a/codepot/src/js/codepot.js +++ b/codepot/src/js/codepot.js @@ -382,6 +382,26 @@ function codepot_htmlspecialchars(string, quote_style, charset, double_encode) { return string; } + +function codepot_addslashes(str) { + // discuss at: http://phpjs.org/functions/addslashes/ + // original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // improved by: Ates Goral (http://magnetiq.com) + // improved by: marrtins + // improved by: Nate + // improved by: Onno Marsman + // improved by: Brett Zamir (http://brett-zamir.me) + // improved by: Oskar Larsson Högfeldt (http://oskar-lh.name/) + // input by: Denny Wardhana + // example 1: addslashes("kevin's birthday"); + // returns 1: "kevin\\'s birthday" + + return (str + '') + .replace(/[\\"']/g, '\\$&') + .replace(/\u0000/g, '\\0'); +} + + function codepot_ascii_to_hex (x) { var r="";