/modules/fckeditor/resources/FCKeditor/editor/filemanager/browser/default/connectors/perl/io.pl

https://github.com/wyona/lenya · Perl · 127 lines · 72 code · 19 blank · 36 comment · 12 complexity · c820e60d7f8f9a5a1ce2d7b8e4bdb55b MD5 · raw file

  1. #####
  2. # FCKeditor - The text editor for internet
  3. # Copyright (C) 2003-2005 Frederico Caldeira Knabben
  4. #
  5. # Licensed under the terms of the GNU Lesser General Public License:
  6. # http://www.opensource.org/licenses/lgpl-license.php
  7. #
  8. # For further information visit:
  9. # http://www.fckeditor.net/
  10. #
  11. # "Support Open Source software. What about a donation today?"
  12. #
  13. # File Name: io.pl
  14. # This is the File Manager Connector for Perl.
  15. #
  16. # File Authors:
  17. # Takashi Yamaguchi (jack@omakase.net)
  18. #####
  19. sub GetUrlFromPath
  20. {
  21. local($resourceType, $folderPath) = @_;
  22. if($resourceType eq '') {
  23. $rmpath = &RemoveFromEnd($GLOBALS{'UserFilesPath'},'/');
  24. return("$rmpath$folderPath");
  25. } else {
  26. return("$GLOBALS{'UserFilesPath'}$resourceType$folderPath");
  27. }
  28. }
  29. sub RemoveExtension
  30. {
  31. local($fileName) = @_;
  32. local($path, $base, $ext);
  33. if($fileName !~ /\./) {
  34. $fileName .= '.';
  35. }
  36. if($fileName =~ /([^\\\/]*)\.(.*)$/) {
  37. $base = $1;
  38. $ext = $2;
  39. if($fileName =~ /(.*)$base\.$ext$/) {
  40. $path = $1;
  41. }
  42. }
  43. return($path,$base,$ext);
  44. }
  45. sub ServerMapFolder
  46. {
  47. local($resourceType,$folderPath) = @_;
  48. # Get the resource type directory.
  49. $sResourceTypePath = $GLOBALS{'UserFilesDirectory'} . $resourceType . '/';
  50. # Ensure that the directory exists.
  51. &CreateServerFolder($sResourceTypePath);
  52. # Return the resource type directory combined with the required path.
  53. $rmpath = &RemoveFromStart($folderPath,'/');
  54. return("$sResourceTypePath$rmpath");
  55. }
  56. sub GetParentFolder
  57. {
  58. local($folderPath) = @_;
  59. $folderPath =~ s/[\/][^\/]+[\/]?$//g;
  60. return $folderPath;
  61. }
  62. sub CreateServerFolder
  63. {
  64. local($folderPath) = @_;
  65. $sParent = &GetParentFolder($folderPath);
  66. # Check if the parent exists, or create it.
  67. if(!(-e $sParent)) {
  68. $sErrorMsg = &CreateServerFolder($sParent);
  69. if($sErrorMsg == 1) {
  70. return(1);
  71. }
  72. }
  73. if(!(-e $folderPath)) {
  74. umask(000);
  75. mkdir("$folderPath",0777);
  76. chmod(0777,"$folderPath");
  77. return(0);
  78. } else {
  79. return(1);
  80. }
  81. }
  82. sub GetRootPath
  83. {
  84. #use Cwd;
  85. # my $dir = getcwd;
  86. # print $dir;
  87. # $dir =~ s/$ENV{'DOCUMENT_ROOT'}//g;
  88. # print $dir;
  89. # return($dir);
  90. # $wk = $0;
  91. # $wk =~ s/\/connector\.cgi//g;
  92. # if($wk) {
  93. # $current_dir = $wk;
  94. # } else {
  95. # $current_dir = `pwd`;
  96. # }
  97. # return($current_dir);
  98. use Cwd;
  99. if($ENV{'DOCUMENT_ROOT'}) {
  100. $dir = $ENV{'DOCUMENT_ROOT'};
  101. } else {
  102. my $dir = getcwd;
  103. $workdir =~ s/\/connector\.cgi//g;
  104. $dir =~ s/$workdir//g;
  105. }
  106. return($dir);
  107. }
  108. 1;