/pigeoncms/Plugins/fckeditor/editor/filemanager/connectors/perl/io.pl

http://pigeoncms.googlecode.com/ · Perl · 141 lines · 81 code · 20 blank · 40 comment · 17 complexity · 2c403f455bd52659423f1ffd01cd7eab MD5 · raw file

  1. #####
  2. # FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. # Copyright (C) 2003-2009 Frederico Caldeira Knabben
  4. #
  5. # == BEGIN LICENSE ==
  6. #
  7. # Licensed under the terms of any of the following licenses at your
  8. # choice:
  9. #
  10. # - GNU General Public License Version 2 or later (the "GPL")
  11. # http://www.gnu.org/licenses/gpl.html
  12. #
  13. # - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14. # http://www.gnu.org/licenses/lgpl.html
  15. #
  16. # - Mozilla Public License Version 1.1 or later (the "MPL")
  17. # http://www.mozilla.org/MPL/MPL-1.1.html
  18. #
  19. # == END LICENSE ==
  20. #
  21. # This is the File Manager Connector for Perl.
  22. #####
  23. sub GetUrlFromPath
  24. {
  25. local($resourceType, $folderPath) = @_;
  26. if($resourceType eq '') {
  27. $rmpath = &RemoveFromEnd($GLOBALS{'UserFilesPath'},'/');
  28. return("$rmpath$folderPath");
  29. } else {
  30. return("$GLOBALS{'UserFilesPath'}$resourceType$folderPath");
  31. }
  32. }
  33. sub RemoveExtension
  34. {
  35. local($fileName) = @_;
  36. local($path, $base, $ext);
  37. if($fileName !~ /\./) {
  38. $fileName .= '.';
  39. }
  40. if($fileName =~ /([^\\\/]*)\.(.*)$/) {
  41. $base = $1;
  42. $ext = $2;
  43. if($fileName =~ /(.*)$base\.$ext$/) {
  44. $path = $1;
  45. }
  46. }
  47. return($path,$base,$ext);
  48. }
  49. sub ServerMapFolder
  50. {
  51. local($resourceType,$folderPath) = @_;
  52. # Get the resource type directory.
  53. $sResourceTypePath = $GLOBALS{'UserFilesDirectory'} . $resourceType . '/';
  54. # Ensure that the directory exists.
  55. &CreateServerFolder($sResourceTypePath);
  56. # Return the resource type directory combined with the required path.
  57. $rmpath = &RemoveFromStart($folderPath,'/');
  58. return("$sResourceTypePath$rmpath");
  59. }
  60. sub GetParentFolder
  61. {
  62. local($folderPath) = @_;
  63. $folderPath =~ s/[\/][^\/]+[\/]?$//g;
  64. return $folderPath;
  65. }
  66. sub CreateServerFolder
  67. {
  68. local($folderPath) = @_;
  69. $sParent = &GetParentFolder($folderPath);
  70. # Check if the parent exists, or create it.
  71. if(!(-e $sParent)) {
  72. $sErrorMsg = &CreateServerFolder($sParent);
  73. if($sErrorMsg == 1) {
  74. return(1);
  75. }
  76. }
  77. if(!(-e $folderPath)) {
  78. if (defined $CHMOD_ON_FOLDER_CREATE && !$CHMOD_ON_FOLDER_CREATE) {
  79. mkdir("$folderPath");
  80. }
  81. else {
  82. umask(000);
  83. if (defined $CHMOD_ON_FOLDER_CREATE) {
  84. mkdir("$folderPath",$CHMOD_ON_FOLDER_CREATE);
  85. }
  86. else {
  87. mkdir("$folderPath",0777);
  88. }
  89. }
  90. return(0);
  91. } else {
  92. return(1);
  93. }
  94. }
  95. sub GetRootPath
  96. {
  97. #use Cwd;
  98. # my $dir = getcwd;
  99. # print $dir;
  100. # $dir =~ s/$ENV{'DOCUMENT_ROOT'}//g;
  101. # print $dir;
  102. # return($dir);
  103. # $wk = $0;
  104. # $wk =~ s/\/connector\.cgi//g;
  105. # if($wk) {
  106. # $current_dir = $wk;
  107. # } else {
  108. # $current_dir = `pwd`;
  109. # }
  110. # return($current_dir);
  111. use Cwd;
  112. if($ENV{'DOCUMENT_ROOT'}) {
  113. $dir = $ENV{'DOCUMENT_ROOT'};
  114. } else {
  115. my $dir = getcwd;
  116. $workdir =~ s/\/connector\.cgi//g;
  117. $dir =~ s/$workdir//g;
  118. }
  119. return($dir);
  120. }
  121. 1;