Déplacement préalable à l'eggification.
[ckeditor.git] / Products / ckeditor / skins / ckeditor / plugins / plinn_image / connectors / plinn / connector.py
diff --git a/Products/ckeditor/skins/ckeditor/plugins/plinn_image/connectors/plinn/connector.py b/Products/ckeditor/skins/ckeditor/plugins/plinn_image/connectors/plinn/connector.py
new file mode 100644 (file)
index 0000000..9c0deb8
--- /dev/null
@@ -0,0 +1,54 @@
+##parameters=command, path, file='', Type='', redirUrl=''
+
+from Products.CMFCore.utils import getToolByName
+
+def replaceXMLEntities(text) :
+       for c, ent in (('<', '&lt;'), ('>', '&gt;'), ('&', '&amp;')) :
+               text = text.replace(c, ent)
+       return text
+
+utool = getToolByName(context, 'portal_url')
+atool = getToolByName(context, 'portal_attachment')
+
+portal = utool.getPortalObject()
+
+ob = portal
+path = path.strip('/')
+
+ob = portal
+path = path.strip('/')
+
+for name in path.split('/') :
+       ob = getattr(ob, name)
+
+if command == 'ls':
+       attachments = atool.getAttachmentsFor(ob)
+       attachments = attachments.objectValues()
+       
+       print '<ls>'
+       for o in attachments :
+               size = o.getThumbnailSize()
+               row = '<row previewUrl="%(previewUrl)s" url="%(url)s" meta_type="%(meta_type)s" width="%(width)d" height="%(height)d">%(title)s</row>' % {
+                               'previewUrl' : '%s/getThumbnail' % o.absolute_url(),
+                               'url' : 'attachments/%s' % o.getId(),
+                               'meta_type' : o.meta_type,
+                               'title' : replaceXMLEntities(o.title_or_id()),
+                               'width' : size['width'],
+                               'height' : size['height']
+                       }
+               print row
+       print '</ls>'
+
+if command == 'upload' :
+       atool.uploadAttachmentFor(ob, file, typeName=Type)
+       return context.REQUEST.RESPONSE.redirect(redirUrl);
+
+if command == 'rm' :
+    ob = context.restrictedTraverse(path)
+    parent = ob.getParentNode()
+    parent.manage_delObjects(ob.getId())
+    print '<done/>'
+       
+    
+context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
+return printed
\ No newline at end of file