Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
upload.FCKeditorQuickUpload Class Reference
Inheritance diagram for upload.FCKeditorQuickUpload:
Inheritance graph
[legend]
Collaboration diagram for upload.FCKeditorQuickUpload:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def doResponse
def setHeader
def uploadFile
def setHttpHeaders
def sendUploadResults

Public Attributes

 userFilesFolder
 webUserFilesFolder
 request
 headers
 environ

Detailed Description

Definition at line 35 of file upload.py.


Member Function Documentation

Definition at line 36 of file upload.py.

00036 
00037        def doResponse(self):
00038               "Main function. Process the request, set headers and return a string as response."
00039               # Check if this connector is disabled
00040               if not(Config.Enabled):
00041                      return self.sendUploadResults(1, "This file uploader is disabled. Please check the \"editor/filemanager/connectors/py/config.py\"")
00042               command = 'QuickUpload'
00043               # The file type (from the QueryString, by default 'File').
00044               resourceType  = self.request.get('Type','File')
00045               currentFolder = "/"
00046               # Check for invalid paths
00047               if currentFolder is None:
00048                      return self.sendUploadResults(102, '', '', "")
00049 
00050               # Check if it is an allowed command
00051               if ( not command in Config.ConfigAllowedCommands ):
00052                      return self.sendUploadResults( 1, '', '', 'The %s command isn\'t allowed' % command )
00053 
00054               if ( not resourceType in Config.ConfigAllowedTypes  ):
00055                      return self.sendUploadResults( 1, '', '', 'Invalid type specified' )
00056 
00057               # Setup paths
00058               self.userFilesFolder = Config.QuickUploadAbsolutePath[resourceType]
00059               self.webUserFilesFolder =  Config.QuickUploadPath[resourceType]
00060               if not self.userFilesFolder: # no absolute path given (dangerous...)
00061                      self.userFilesFolder = mapServerPath(self.environ,
00062                                                                self.webUserFilesFolder)
00063 
00064               # Ensure that the directory exists.
00065               if not os.path.exists(self.userFilesFolder):
00066                      try:
00067                             self.createServerFoldercreateServerFolder( self.userFilesFolder )
00068                      except:
00069                             return self.sendError(1, "This connector couldn\'t access to local user\'s files directories.  Please check the UserFilesAbsolutePath in \"editor/filemanager/connectors/py/config.py\" and try again. ")
00070 
00071               # File upload doesn't have to return XML, so intercept here
00072               return self.uploadFile(resourceType, currentFolder)
00073 
# Running from command line (plain old CGI)

Here is the call graph for this function:

def fckoutput.BaseHtmlMixin.sendUploadResults (   self,
  errorNo = 0,
  fileUrl = '',
  fileName = '',
  customMsg = '' 
) [inherited]

Definition at line 104 of file fckoutput.py.

00104 
00105        def sendUploadResults( self, errorNo = 0, fileUrl = '', fileName = '', customMsg = '' ):
00106               self.setHttpHeaders("text/html")
00107               "This is the function that sends the results of the uploading process"
00108 
00109               "Minified version of the document.domain automatic fix script (#1919)."
00110               "The original script can be found at _dev/domain_fix_template.js"
00111               return """<script type="text/javascript">
00112                      (function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();
00113 
00114                      window.parent.OnUploadCompleted(%(errorNumber)s,"%(fileUrl)s","%(fileName)s","%(customMsg)s");
00115                      </script>""" % {
00116                      'errorNumber': errorNo,
00117                      'fileUrl': fileUrl.replace ('"', '\\"'),
00118                      'fileName': fileName.replace ( '"', '\\"' ) ,
00119                      'customMsg': customMsg.replace ( '"', '\\"' ),
00120                      }

Here is the call graph for this function:

Here is the caller graph for this function:

def fckconnector.FCKeditorConnectorBase.setHeader (   self,
  key,
  value 
) [inherited]

Reimplemented in zope.FCKeditorConnectorZope.

Definition at line 49 of file fckconnector.py.

00049 
00050        def setHeader(self, key, value):
00051               self.headers.append ((key, value))
00052               return

Here is the caller graph for this function:

def fckoutput.BaseHttpMixin.setHttpHeaders (   self,
  content_type = 'text/xml' 
) [inherited]

Definition at line 50 of file fckoutput.py.

00050 
00051        def setHttpHeaders(self, content_type='text/xml'):
00052               "Purpose: to prepare the headers for the xml to return"
00053               # Prevent the browser from caching the result.
00054               # Date in the past
00055               self.setHeader('Expires','Mon, 26 Jul 1997 05:00:00 GMT')
00056               # always modified
00057               self.setHeader('Last-Modified',strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime()))
00058               # HTTP/1.1
00059               self.setHeader('Cache-Control','no-store, no-cache, must-revalidate')
00060               self.setHeader('Cache-Control','post-check=0, pre-check=0')
00061               # HTTP/1.0
00062               self.setHeader('Pragma','no-cache')
00063 
00064               # Set the response format.
00065               self.setHeader( 'Content-Type', content_type + '; charset=utf-8' )
00066               return

Here is the call graph for this function:

Here is the caller graph for this function:

def fckcommands.UploadFileCommandMixin.uploadFile (   self,
  resourceType,
  currentFolder 
) [inherited]
Purpose: command to upload files to server (same as FileUpload)

Definition at line 131 of file fckcommands.py.

00131 
00132        def uploadFile(self, resourceType, currentFolder):
00133               """
00134               Purpose: command to upload files to server (same as FileUpload)
00135               """
00136               errorNo = 0
00137               if self.request.has_key("NewFile"):
00138                      # newFile has all the contents we need
00139                      newFile = self.request.get("NewFile", "")
00140                      # Get the file name
00141                      newFileName = newFile.filename
00142                      newFileName = sanitizeFileName( newFileName )
00143                      newFileNameOnly = removeExtension(newFileName)
00144                      newFileExtension = getExtension(newFileName).lower()
00145                      allowedExtensions = Config.AllowedExtensions[resourceType]
00146                      deniedExtensions = Config.DeniedExtensions[resourceType]
00147 
00148                      if (allowedExtensions):
00149                             # Check for allowed
00150                             isAllowed = False
00151                             if (newFileExtension in allowedExtensions):
00152                                    isAllowed = True
00153                      elif (deniedExtensions):
00154                             # Check for denied
00155                             isAllowed = True
00156                             if (newFileExtension in deniedExtensions):
00157                                    isAllowed = False
00158                      else:
00159                             # No extension limitations
00160                             isAllowed = True
00161 
00162                      if (isAllowed):
00163                             # Upload to operating system
00164                             # Map the virtual path to the local server path
00165                             currentFolderPath = mapServerFolder(self.userFilesFolder, currentFolder)
00166                             i = 0
00167                             while (True):
00168                                    newFilePath = os.path.join (currentFolderPath,newFileName)
00169                                    if os.path.exists(newFilePath):
00170                                           i += 1
00171                                           newFileName = "%s(%d).%s" % (
00172                                                         newFileNameOnly, i, newFileExtension
00173                                                         )
00174                                           errorNo= 201 # file renamed
00175                                    else:
00176                                           # Read file contents and write to the desired path (similar to php's move_uploaded_file)
00177                                           fout = file(newFilePath, 'wb')
00178                                           while (True):
00179                                                  chunk = newFile.file.read(100000)
00180                                                  if not chunk: break
00181                                                  fout.write (chunk)
00182                                           fout.close()
00183 
00184                                           if os.path.exists ( newFilePath ):
00185                                                  doChmod = False
00186                                                  try:
00187                                                         doChmod = Config.ChmodOnUpload
00188                                                         permissions = Config.ChmodOnUpload
00189                                                  except AttributeError: #ChmodOnUpload undefined
00190                                                         doChmod = True
00191                                                         permissions = 0755
00192                                                  if ( doChmod ):
00193                                                         oldumask = os.umask(0)
00194                                                         os.chmod( newFilePath, permissions )
00195                                                         os.umask( oldumask )
00196 
00197                                           newFileUrl = combinePaths(self.webUserFilesFolder, currentFolder) + newFileName
00198 
00199                                           return self.sendUploadResults( errorNo , newFileUrl, newFileName )
00200                      else:
00201                             return self.sendUploadResults( errorNo = 202, customMsg = "" )
00202               else:
00203                      return self.sendUploadResults( errorNo = 202, customMsg = "No File" )

Here is the call graph for this function:


Member Data Documentation

Definition at line 43 of file fckconnector.py.

Definition at line 41 of file fckconnector.py.

Reimplemented in zope.FCKeditorConnectorZope.

Definition at line 40 of file fckconnector.py.

Definition at line 57 of file upload.py.

Definition at line 58 of file upload.py.


The documentation for this class was generated from the following file: