From 8e8ec1523f039231d5ceab9289dd7159610602d8 Mon Sep 17 00:00:00 2001
From: Erlend Dalen
Date: Mon, 27 May 2013 12:49:25 +0200
Subject: [PATCH] Issue #25: Filter on the current site.
Making sure that the image plugin use the site filter so that only
images that are added to the current site can be used.
---
media_tree/admin/filenode_admin.py | 6 +-
media_tree/contrib/cms_plugins/cms_app.py | 9 +
.../media_tree_image/cms_plugins.py | 7 +
.../cms_plugins/media_tree_image/models.py | 8 +
media_tree/contrib/views/detail/__init__.py | 2 +
media_tree/fields.py | 2 +-
media_tree/manage.py | 9 +
media_tree/middleware.py | 7 +
media_tree/models.py | 4 +-
.../lib/swfupload/core changelog.txt | 315 ++++
.../lib/swfupload/documentation/index.html | 1332 +++++++++++++
.../swfupload/plugins/SWFObject License.txt | 4 +
.../swfupload/plugins/swfupload.cookies.js | 53 +
.../lib/swfupload/plugins/swfupload.proxy.js | 96 +
.../lib/swfupload/plugins/swfupload.queue.js | 98 +
.../lib/swfupload/plugins/swfupload.speed.js | 346 ++++
.../lib/swfupload/swfupload license.txt | 12 +
.../swfupload_fp10/AsyncJPEGEncoder.as | 761 ++++++++
.../swfupload_fp10/EncodeCompleteEvent.as | 28 +
.../swfupload/swfupload_fp10/ExternalCall.as | 144 ++
.../lib/swfupload/swfupload_fp10/FileItem.as | 126 ++
.../swfupload/swfupload_fp10/ImageResizer.as | 203 ++
.../swfupload_fp10/ImageResizerEvent.as | 20 +
.../swfupload_fp10/MultipartURLLoader.as | 352 ++++
.../swfupload/swfupload_fp10/PNGEncoder.as | 295 +++
.../swfupload_fp10/SWFUpload FP10.as3proj | 81 +
.../lib/swfupload/swfupload_fp10/SWFUpload.as | 1679 +++++++++++++++++
.../lib/swfupload/swfupload_fp10/deploy.bat | 4 +
.../swfupload/swfupload_fp10/jpegencoder.swc | Bin 0 -> 167837 bytes
.../lib/swfupload/swfupload_fp10/swfupload.js | 1132 +++++++++++
.../swfupload/swfupload_fp10/swfupload.swf | Bin 0 -> 186661 bytes
.../swfupload/swfupload_fp9/ExternalCall.as | 140 ++
.../lib/swfupload/swfupload_fp9/FileItem.as | 123 ++
.../swfupload_fp9/SWFUpload FP9.as3proj | 81 +
.../lib/swfupload/swfupload_fp9/SWFUpload.as | 1572 +++++++++++++++
.../lib/swfupload/swfupload_fp9/deploy.bat | 4 +
.../swfupload/swfupload_fp9/swfupload_fp9.swf | Bin 0 -> 13333 bytes
.../change_list_results_thumbnails.html | 41 +
.../templates/media_tree/filenode/image.html | 13 +
media_tree/urls.py | 19 +
media_tree/views.py | 17 +
41 files changed, 9141 insertions(+), 4 deletions(-)
create mode 100644 media_tree/contrib/cms_plugins/cms_app.py
create mode 100644 media_tree/manage.py
create mode 100644 media_tree/middleware.py
create mode 100644 media_tree/static/media_tree/lib/swfupload/core changelog.txt
create mode 100644 media_tree/static/media_tree/lib/swfupload/documentation/index.html
create mode 100644 media_tree/static/media_tree/lib/swfupload/plugins/SWFObject License.txt
create mode 100644 media_tree/static/media_tree/lib/swfupload/plugins/swfupload.cookies.js
create mode 100644 media_tree/static/media_tree/lib/swfupload/plugins/swfupload.proxy.js
create mode 100644 media_tree/static/media_tree/lib/swfupload/plugins/swfupload.queue.js
create mode 100644 media_tree/static/media_tree/lib/swfupload/plugins/swfupload.speed.js
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload license.txt
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/AsyncJPEGEncoder.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/EncodeCompleteEvent.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ExternalCall.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/FileItem.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizer.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizerEvent.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/MultipartURLLoader.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/PNGEncoder.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload FP10.as3proj
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/deploy.bat
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/jpegencoder.swc
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/swfupload.js
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp10/swfupload.swf
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp9/ExternalCall.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp9/FileItem.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp9/SWFUpload FP9.as3proj
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp9/SWFUpload.as
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp9/deploy.bat
create mode 100644 media_tree/static/media_tree/lib/swfupload/swfupload_fp9/swfupload_fp9.swf
create mode 100644 media_tree/templates/admin/media_tree/filenode/change_list_results_thumbnails.html
create mode 100644 media_tree/templates/media_tree/filenode/image.html
create mode 100644 media_tree/urls.py
create mode 100644 media_tree/views.py
diff --git a/media_tree/admin/filenode_admin.py b/media_tree/admin/filenode_admin.py
index 6493f45..acd0980 100644
--- a/media_tree/admin/filenode_admin.py
+++ b/media_tree/admin/filenode_admin.py
@@ -11,7 +11,7 @@
# TODO: Ordering of tree by column (within parent) should be possible
# TODO: Refactor SWFUpload stuff as extension. This would require signals calls
# to be called in the FileNodeAdmin view methods.
-
+from django.contrib.sites.models import Site
from media_tree.fields import FileNodeChoiceField
from media_tree.models import FileNode
@@ -132,6 +132,10 @@ def __init__(self, *args, **kwargs):
# http://stackoverflow.com/questions/1618728/disable-link-to-edit-object-in-djangos-admin-display-list-only
self.list_display_links = (None, )
+ def queryset(self, request):
+ qs = super(FileNodeAdmin, self).queryset(request)
+ return qs.filter(site=Site.objects.get_current())
+
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'parent' and issubclass(db_field.rel.to, FileNode):
# overriding formfield_for_dbfield, thus bypassign both Django's and mptt's
diff --git a/media_tree/contrib/cms_plugins/cms_app.py b/media_tree/contrib/cms_plugins/cms_app.py
new file mode 100644
index 0000000..1a36eb4
--- /dev/null
+++ b/media_tree/contrib/cms_plugins/cms_app.py
@@ -0,0 +1,9 @@
+from cms.app_base import CMSApp
+from cms.apphook_pool import apphook_pool
+from django.utils.translation import ugettext_lazy as _
+
+class MediaTreeApphook(CMSApp):
+ name = _("Media Tree")
+ urls = ["media_tree.urls"]
+
+apphook_pool.register(MediaTreeApphook)
diff --git a/media_tree/contrib/cms_plugins/media_tree_image/cms_plugins.py b/media_tree/contrib/cms_plugins/media_tree_image/cms_plugins.py
index 5a0efa7..e64dffe 100644
--- a/media_tree/contrib/cms_plugins/media_tree_image/cms_plugins.py
+++ b/media_tree/contrib/cms_plugins/media_tree_image/cms_plugins.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.contrib.cms_plugins.media_tree_image.models import MediaTreeImage
from media_tree.contrib.cms_plugins.forms import MediaTreePluginFormBase
from media_tree.contrib.views.detail.image import ImageNodeDetailMixin
@@ -9,9 +10,15 @@
from django.utils.translation import ugettext_lazy as _
# TODO: Solve image_detail with get_absolute_url()?
+from media_tree.models import FileNode
class MediaTreeImagePluginForm(MediaTreePluginFormBase):
+
+ def __init__(self, *args, **kwargs):
+ super(MediaTreeImagePluginForm, self).__init__(*args, **kwargs)
+ self.fields['node'].queryset = FileNode.objects.filter(site=Site.objects.get_current())
+
class Meta:
model = MediaTreeImage
diff --git a/media_tree/contrib/cms_plugins/media_tree_image/models.py b/media_tree/contrib/cms_plugins/media_tree_image/models.py
index 9da1cd9..c41bd2c 100644
--- a/media_tree/contrib/cms_plugins/media_tree_image/models.py
+++ b/media_tree/contrib/cms_plugins/media_tree_image/models.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree import media_types
from media_tree.contrib.cms_plugins import settings as plugins_settings
from media_tree.fields import FileNodeForeignKey, DimensionField
@@ -6,6 +7,11 @@
from django.utils.translation import ugettext_lazy as _
+class MediaTreeImageSiteManager(models.Manager):
+ def get_query_set(self):
+ return super(MediaTreeImageSiteManager, self).get_query_set().filter(node__site=Site.objects.get_current())
+
+
class MediaTreeImage(CMSPlugin):
node = FileNodeForeignKey(allowed_media_types=(media_types.SUPPORTED_IMAGE,), verbose_name=_('file'))
link_type = models.CharField(_('link type'), max_length=1, blank=True, null=True, default=plugins_settings.MEDIA_TREE_CMS_PLUGIN_LINK_TYPE_DEFAULT, choices=plugins_settings.MEDIA_TREE_CMS_PLUGIN_LINK_TYPE_CHOICES, help_text=_('Makes the image a clickable link.'))
@@ -16,5 +22,7 @@ class MediaTreeImage(CMSPlugin):
height = DimensionField(_('max. height'), null=True, blank=True, help_text=_('You can leave this empty to use an automatically determined image height.'))
render_template = models.CharField(_("template"), max_length=100, choices=None, blank=True, null=True, help_text=_('Template used to render the image.'))
+ objects = MediaTreeImageSiteManager()
+
def __unicode__(self):
return self.node.__unicode__()
diff --git a/media_tree/contrib/views/detail/__init__.py b/media_tree/contrib/views/detail/__init__.py
index 2a83cb0..99bbc68 100644
--- a/media_tree/contrib/views/detail/__init__.py
+++ b/media_tree/contrib/views/detail/__init__.py
@@ -1,3 +1,4 @@
+from django.contrib.sites.models import Site
from media_tree.models import FileNode
from media_tree.contrib.views.mixin_base import PluginMixin
from django.views.generic.detail import DetailView
@@ -75,6 +76,7 @@ def get_object(self, queryset=None):
def get_queryset(self, *args, **kwargs):
queryset = super(FileNodeDetailView, self).get_queryset(*args, **kwargs)
+ queryset = queryset.filter(node__site=Site.objects.get_current())
kwargs = {}
if self.filter_node_types:
kwargs['node_type__in'] = self.filter_node_types
diff --git a/media_tree/fields.py b/media_tree/fields.py
index 774882f..1acbc4e 100644
--- a/media_tree/fields.py
+++ b/media_tree/fields.py
@@ -31,7 +31,7 @@ def __init__(self, allowed_node_types=None, allowed_media_types=None, allowed_ex
self.allowed_node_types = allowed_node_types
self.allowed_media_types = allowed_media_types
self.allowed_extensions = allowed_extensions
- kwargs['level_indicator'] = level_indicator;
+ kwargs['level_indicator'] = level_indicator
if not kwargs.has_key('widget'):
kwargs['widget'] = self.widget
diff --git a/media_tree/manage.py b/media_tree/manage.py
new file mode 100644
index 0000000..feefca0
--- /dev/null
+++ b/media_tree/manage.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+import os, sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "datakortet.settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
diff --git a/media_tree/middleware.py b/media_tree/middleware.py
new file mode 100644
index 0000000..d767165
--- /dev/null
+++ b/media_tree/middleware.py
@@ -0,0 +1,7 @@
+from django.conf import settings
+
+class SessionPostMiddleware(object):
+
+ def process_request(self, request):
+ if not request.COOKIES.has_key(settings.SESSION_COOKIE_NAME) and request.POST.has_key(settings.SESSION_COOKIE_NAME):
+ request.COOKIES[settings.SESSION_COOKIE_NAME] = request.POST[settings.SESSION_COOKIE_NAME]
\ No newline at end of file
diff --git a/media_tree/models.py b/media_tree/models.py
index 70ee009..0b4af86 100644
--- a/media_tree/models.py
+++ b/media_tree/models.py
@@ -87,7 +87,7 @@ def filter(self, *args, **kwargs):
"""
if 'path' in kwargs:
kwargs = self.get_filter_args_with_path(False, **kwargs)
- return super(FileNodeManager, self).filter(*args, **kwargs)
+ return super(FileNodeManager, self).filter(site=Site.objects.get_current()).filter(*args, **kwargs)
def exclude(self, *args, **kwargs):
"""
@@ -98,7 +98,7 @@ def exclude(self, *args, **kwargs):
"""
if 'path' in kwargs:
kwargs = self.get_filter_args_with_path(False, **kwargs)
- return super(FileNodeManager, self).exclude(*args, **kwargs)
+ return super(FileNodeManager, self).filter(site=Site.objects.get_current()).exclude(*args, **kwargs)
def get(self, *args, **kwargs):
"""
diff --git a/media_tree/static/media_tree/lib/swfupload/core changelog.txt b/media_tree/static/media_tree/lib/swfupload/core changelog.txt
new file mode 100644
index 0000000..15695f9
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/core changelog.txt
@@ -0,0 +1,315 @@
+ * SWFUpload Core, January 2009, www.swfupload.org, swfupload.googlecode.com
+
+ * --------- Version 2.5.0-----------
+ * + Added Client Side thumbnail generation and uploading and related settings
+ * -- Thanks to matzes for getting standard HTTP uploading to work
+ * + Added Alchemy based JPEG Encoder (which is much much faster)
+ * = Fixed double encoding of settings issue
+ * = Improved movieElement grabbing
+ * - Removed settings clone as it is unreliable
+ * = Fixed speed plugin so it checks for a file before extending it
+ * + Progress event manually fired for 100% if not fired by Flash
+ * + mouseClick, mouseOver, mouseOut event and handler settings added
+ * - Removed BUTTON_ACTION.JAVASCRIPT constant and button_action_handler. These are replaced by the mouseClick event
+ * + Added proxy plugin
+ * - Removed swfobject plugin
+ * + Integrated swfobject with core code
+ * + Added swfupload_preload_handler event/setting
+ * + Added swfupload_load_failed_handler event/setting
+ * + Added flash9_url to support SWF split to support Flash Player 9 and Flash Player 10
+ * = Fixed param encoding issue
+ * = Fixed button cursor when no button image was loaded
+
+
+ * --------- Version 2.2.1-----------
+ * + Added requeueUpload and updated documentation
+ * + Added button_action type of JAVASCRIPT and a buttonAction event to trigger a JavaScript function when the Flash Button is clicked
+ * = Updated destroy method to make sure the testExternalInterface timer is cleared
+ * = Also fixed destroy so the element is removed in non-IE browsers
+ * = Also fixed destroy method to call cleanUp method rather than duplicating the code
+ * = Fixed scope issue in cleanUp method.
+ * = Fixed bug in Queue Plugin that prevented the queueComplete event from firing
+ * + The place holder element is now replaced with the same type of flow element (div for block, span for inline)
+
+
+ * --------- Version 2.2.0.1-----------
+ * - Removed requeueUpload due to bugs/poor testing
+ * = Fixed namespace conflict that broke stopUpload
+
+ * --------- Version 2.2.0-----------
+ * + Added button_placeholder setting that accepts a DOM element.
+ * + Added ability to requeue any file (including some improvement to internal queue state tracking)
+ * + UploadErrors caused by a missing upload_url now causes the file to be requeued automatically
+ * + Added preserve_relative_urls setting
+ * + SWFUpload now converts relative URLs to absolute URLs to avoid issues with Flash Player interpreting it differently on some clients
+ * + Added assume_success_timeout setting which allows uploadSuccess to be called after a timeout if, for some reason Flash ignores the server's response
+ * An additional parameter has been added to the uploadSuccess event to indicate whether a response was received or success was assumed.
+
+ * --------- Version 2.2.0 Beta 2 ~ 5-----------
+ * = Fixed a Queue Limit bug
+ * + Improved internal event handling code so uploadSuccess fires even when not content is returned from the server (*woot*, except for Macs)
+ * = Fixed issues in Destroy
+ * = Fixed issues with Queue Plugin
+ * + Added periodic checks of the ExternalInterface
+ * + Improved IE memory leak prevention code
+ * + Added Speed Plugin
+ * = Updated Queue Plugin for better multi-plugin compatibility
+
+ * --------- Version 2.2.0 Beta 1-----------
+ * + Added Flash Player 10 Support
+ * = Added setting for defining a button image
+ * = Added setting for defining button text
+ * = Added setting for defining button width, height and padding
+ * = Added setting for defining what element the Flash Movie should replace
+ * = Added setting for defining flash wmode
+ * = Added setting for defining the mouse cursor
+ * + Added prevent_swf_caching setting as a work-around for issues in Avant Browser (and other IE based browser)
+ * + Added setting for accepting HTTP Status codes other than 200 as successful
+ * + Added parameter to cancelUpload that allows the uploadError event for cancelled uploads to be supressed
+ * + Added pro-active memory leak fix for IE and fixed problems with the destroy function (credits to steffen for patches and testing)
+ * + Replaced callFlash with CallFunction (using the internal function that Flash uses). Based on code from MooTools.
+ * = Fixed bug in the Queue plugin that breaks startUpload when passing a file id.
+ * + Updated Queue plugin to stop the queue if false is returned from the uploadStart handler.
+ * = Fixed small issues in SWFObject plugin
+ * = Fixed issue with ExternalInterface string escaping
+ * - Dropped Graceful Degradation Plugin
+ * - Dropped v1.0.2 Plugin
+ * - Dropped Flash Player 8 support
+
+ * --------- Version 2.1.0 -----------
+ * = Fixed GET values so they are escaped properly
+ * + Added destroy function
+ * = Added exception handling around browse() calls
+ * = Minor code cleanup
+ * + Split Core and Demos
+
+ * --------- Version 2.1.0 Beta 2-----------
+ * = Fixed bug in XHTML fix where it wasn't split correctly by Flash
+ * = Fixed file params "undefined" in debug output
+ * + Added requeue_on_error settings so HTTP/IO/Security errors requeue the file instead of discarding it.
+ This will affect the queue plugin (if an error is occurring the file will be reuploaded and reuploaded).
+ * = Fixed HTTP/IO error behavior. We'll see how this goes Flash 9 is supposed to call HTTPError followed by an IO error but I suspect they come out of orde sometimes.
+ * = Fixed invalid characters in file param names. Worked around flash bug by escaping the names. Should be transparent to devs.
+ * = Fixed missing upload URL logic so it fires consistently
+ * = Fixed file params not being sent when useQueryString is true
+ * + Added SWFObject plugin and demo.
+ * + Added CookieBug demo to demonstrate what they bug really is all about.
+ * + Added VB.Net version of the Application Demo
+
+
+ * --------- Version 2.1.0 Beta 1-----------
+ * + Added allowScriptAccess="always" to the embed/object elements so the SWF can be served from different domains.
+ * = Fixed a type-o in the debug output that prevented the instance id (movieName) from displaying. - Thx Joel
+ * + Rewrote SWFUpload.js for better code reuse based on sample code from batiste.bieler (thanks!!!)
+ * + Added queueComplete event to the Queue Plugin
+ * + Added Simple Upload demo
+ * = JSLinted all the JavaScript code
+ * + Added use_query_string setting (and setUseQueryString function) that forces post_param and file_param values to be sent on the query_string instead of the post (for Flash 9 version)
+ * = Fixed file.type and date properties so a default value is provided (rather than null) when no value is provided by flash.
+ * = Fixed misc bugs in the demos
+ * = Fixed ExternalInterface calls being made available for Flash 9 versions <9.0.28 which aren't supported
+ * + Fixed use of & producing invalid XHTML in the
+
+ SWFUpload is different from other Flash based upload tools because of the philosophy
+ behind its design. SWFUpload gives developers control by leaving the UI in the browser (as much as possible).
+ Developers can use XHTML, CSS, and JavaScript to tailor the upload UI to the needs and
+ style of their site. Upload status updates are made through a set of simple JavaScript events.
+ The developer uses these events to update the webpage as the file upload progresses.
+
+
+ Unfortunately Flash Player 10 has forced us have one button in a flash movie in order to trigger the file browser dialog window. SWFUpload
+ still empowers the devloper by provding the ability the button and overlay text from JavaScript.
+
+
+
SWFUpload v2
+
+ SWFUpload v2 includes new advanced features, improved stability, Flash Player
+ bug work-arounds and a helpful set of Plug-ins. New features include:
+
+
+
+
Flash Player 10 security compatibility.
+
The ability to send additional POST values with the uploads.
+
Sending per file POST values.
+
Complete set of events.
+
All settings dynamically updateable.
+
Retrieve result data from the server.
+
Stop an upload without cancelling.
+
Upload files in any order.
+
Multi- & Single-file selection dialogs.
+
Queue size, files uploaded and file size limits.
+
Properly handling of zero-byte files.
+
Pre-upload validation event.
+
Work-arounds for bugs in Flash and Browser.
+
+
+
+
Overview
+
HTML Upload
+
+ The standard HTML upload input box provides a box and a button to the user for selecting a file.
+ The file is submitted with the form. The entire file must be uploaded before the next
+ page is displayed. No pre-upload validation can be made on the file (e.g., file size limits or valid extensions).
+ Very little feedback is given to the user while the file uploads.
+
+
+ The usage pattern for standard HTML uploads is simple, straight forward, and supported by nearly all browser.
+
+
SWFUpload
+
+ SWFUpload uses a Flash movie to handle file selection and upload. A customizable button is displayed by the
+ Flash movie that activates Flashes advanced file selection dialog window.
+ The file selection dialog is configured to allow the user select to a single file or multiple files.
+ The file types can be restricted so users only select the appropriate files (e.g., *.jpg;*.gif).
+
+
+ Once selected each file is validated and queued. As the file is uploaded by Flash
+ several JavaScript events are fired which the developer handles in order to update the page's UI allowing you to provide
+ upload status and error messages in real-time.
+
+
+ The uploaded file is submitted separately from the rest of the page and form. Each file is uploaded
+ individually keeping the server-side upload handling script simple. Since Flash is providing the upload
+ service the page does not have to be submitted or reloaded. The usage pattern for SWFUpload is more
+ like that of an AJAX application than that of a standard HTML form. The page's form will be processed
+ separately from the file upload.
+
+
Getting Started
+
SWFUpload is not a drag & drop upload control. It requires knowledge of JavaScript and the DOM. Several demos are available that
+ show some of the things SWFUpload is capable of and how to accomplish common tasks.
+
+
SWFUpload consists of 4 pieces:
+
+
Initialization and Settings (JavaScript)
+
JavaScript library: SWFUpload.js
+
Flash Control: swfupload.swf & swfupload_fp9.swf
+
The Event Handlers (JavaScript)
+
+
+
Most problems implementing SWFUpload are caused by incorrect settings, poorly built event handlers, Flash/Browser Bugs, or server configuration.
+
+
Initialization and Settings
+
SWFUpload must be initialized on the page. This is commonly done in the window.onload event. The SWFUpload constructor takes a settings object.
+ The settings object can be passed directly to the constructor as an object literal.
+
A reference to the initialized SWFUpload object should be kept as it is needed to start uploads and to control other aspects of SWFUpload.
+
+
Example: Initializing SWFUpload with an object literal
The SWFUpload JavaScript library dynamically loads the Flash Control (swfupload.swf/swfupload_fp9.swf).
+
+
The location of the Flash Control file must be provided in the SWFUpload settings object during setup.
+
+
The Flash Control is a small Flash Movie that handles file browsing, validation and upload. It appears on the page as
+ a button and communicates with JavaScript to notify the browser of upload status and other events.
+
+
New ActionScript syntax and classes require us to target Flash Player 10 and Flash Player 9 separately. SWFUpload will detect the installed version of flash and load the appropriate Flash Control.
+
+
Use the flash_url and flash9_url settings to defined custom locations and file names for the swfupload.swf and swfupload_fp9.swf files.
+
+
The Event Handlers
+
+
Developers must create a set of JavaScript functions that handle SWFUpload events. These functions are called as different important events occur.
+
+
By handling the SWFUpload events developers can provide feedback regarding the upload progress, error messages, and upload completion. Developers should not
+ overwrite functions stored in SWFUpload.prototype. Instead create your own set of functions and pass references to them in the settings object.
+
+
Example: SWFUpload event handlers and initialization.
+
+ // The uploadStart event handler. This function variable is assigned to upload_start_handler in the settings object
+var myCustomUploadStartEventHandler = function (file) {
+ var continue_with_upload;
+
+ if (file.name === "the sky is blue") {
+ continue_with_upload = true;
+ } else {
+ continue_with_upload = false;
+ }
+
+ return continue_with_upload;
+};
+
+// The uploadSuccess event handler. This function variable is assigned to upload_success_handler in the settings object
+var myCustomUploadSuccessEventHandler = function (file, server_data, receivedResponse) {
+ alert("The file " + file.name + " has been delivered to the server. The server responded with " + server_data);
+};
+
+// Create the SWFUpload Object
+var swfu = new SWFUpload({
+ upload_url : "http://www.swfupload.org/upload.php",
+ flash_url : "http://www.swfupload.org/swfupload.swf",
+ flash9_url : "http://www.swfupload.org/swfupload_fp9.swf",
+ file_size_limit : "200 MB",
+
+ upload_start_handler : myCustomUploadStartEventHandler,
+ upload_success_handler : myCustomUploadSuccessEventHandler
+});
+
+
+
SWFUpload JavaScript Object
+
+
Constructor
+
+
SWFUpload(settings object)
+
Returns: A SWFUpload instance
+ var swfupload_instance = new SWFUpload(settings_object);
+
+
Globals and Constants
+
+ Several globals and constants are associated with the SWFUpload object. These are useful for
+ advanced SWFUpload applications and for handling errors. These are considered read-only.
+
+
SWFUpload.instances
+
SWFUpload.instances is an object containing a reference to each SWFUpload instance loaded on a page. The Flash Player
+ relies on this object in order to call the correct event handlers. SWFUpload.instances indexes by the movieName property.
+
+
SWFUpload.movieCount
+
SWFUpload.movieCount is a global that tracks the number on SWFUpload instances that have been created and helps to ensure each movie is
+ given a unique movieName.
+
+
SWFUpload.QUEUE_ERROR
+
SWFUpload.QUEUE_ERROR is a simple object that contains Queue Error code constants. It is generally used to determine which error code was sent
+ in the fileQueueError event.
+
+
+
QUEUE_LIMIT_EXCEEDED - indicates that the user has attempted to queue more files that is allowed by the settings. Once files have been updated and removed from the queue the user is again allowed to queue additional files.
+
FILE_EXCEEDS_SIZE_LIMIT - indicates the selected file is larger than is allwed by the file_size_limit.
+
ZERO_BYTE_FILE - indicates that the selected file is empty. The Flash Player cannot handle empty files and the file is rejected. Windows Shortcut files may also trigger this error.
+
INVALID_FILETYPE - The selected file's extension does not match a valid extension from the file_types setting. User's can circumvent the file_types restriction by manually entering a file name.
+
+
+
SWFUpload.UPLOAD_ERROR
+
SWFUpload.UPLOAD_ERROR is a simple object that contains Upload Error code constants. It is generally used to determine which error code was sent
+ in the uploadError event.
+
+
+
HTTP_ERROR - The file upload was attempted but the server did not return a 200 status code.
+
MISSING_UPLOAD_URL - The upload_url setting was not set.
+
IO_ERROR - Some kind of error occurred while reading or transmitting the file. This most commonly occurs when the server unexpectedly terminates the connection.
+
SECURITY_ERROR - The upload violates a security restriction. This error is rare.
+
UPLOAD_LIMIT_EXCEEDED - The user has attempted to upload more files than is allowed by the file_upload_limit setting.
+
UPLOAD_FAILED - The attempt to initiate the upload caused an error. This error is rare.
+
SPECIFIED_FILE_ID_NOT_FOUND - A file ID was passed to startUpload but that file ID could not be found.
+
FILE_VALIDATION_FAILED - False was returned from the uploadStart event
+
FILE_CANCELLED - cancelUpload was called
+
UPLOAD_STOPPED - stopUpload was called.
+
RESIZE_ERROR - An error occurred resizing an image
+
+
+
SWFUpload.FILE_STATUS
+
SWFUpload.FILE_STATUS is a simple object that contains File Status code constants. It can be used to check the file status property on the File object.
+
+
+
QUEUED - indicates the this file is waiting in the queue.
+
IN_PROGRESS - indicates that this file is currently being uploaded.
+
ERROR - indicates that this file caused a queue or upload error.
+
COMPLETE - indicates that this file was successfully transmitted to the server.
+
CANCELLED - indicates that this file was cancelled by a call to cancelUpload.
+
+
+
SWFUpload.UPLOAD_TYPE
+
SWFUpload.UPLOAD_TYPE is a simple object that contains Upload Type constants. It can be used to check the upload type property on the File object.
+
+
+
NORMAL - a normal SWFUpload upload
+
RESIZED - a resized image upload. The data was not sent as an HTTP upload but as a simple post.
+
+
+
SWFUpload.BUTTON_ACTION
+
SWFUpload.BUTTON_ACTION is a simple object that contains button action code constants. It is used with the button_action setting to set the behavior of the Flash based file dialog button.
+
+
+
SELECT_FILE - when the Flash button is clicked the file dialog will only allow a single file to be selected. The mouseClick event is not fired in this case.
+
SELECT_FILES - when the Flash button is clicked the file dialog allows multiple files to be selected. The mouseClick event is not fired in this case.
+
START_UPLOAD - when the Flash button is clicked the first queued file will be uploaded. The mouseClick event is not fired in this case.
+
NONE - when the Flash button is clicked the mouseClick event will be fired.
+
JAVASCRIPT - same as the NONE action. This value is deprecated.
+
+
+
SWFUpload.CURSOR
+
SWFUpload.CURSOR is a simple object that contains button cursor code constants. It is used with the button_cursor setting to set the mouse cursor when hovering over the Flash button.
+
+
+
ARROW - the cursor will display as an arrow pointer
+
HAND - the cursor will display has a finger/hand pointer
+
+
+
SWFUpload.WINDOW_MODE
+
SWFUpload.WINDOW_MODE is a simple object that contains button movie wmode parameter constants. It is used to tell the browser how to display the Flash Movie.
+
The some WINDOW_MODE/WMODE settings can cause problems in some browsers. See the Known Issues.
+
+
+
WINDOW is the default mode. The movie is drawn over the top of all other elements on the page.
+
OPAQUE causes the movie to be rendered in the page allowing other elements to cover up the button.
+
TRANSPARENT the button background is rendered transparent allowing html elements under the button to show through.
+
+
+
SWFUpload.RESIZE_ENCODING
+
SWFUpload.RESIZE_ENCODING is a simple object that contains resize encoding type constants. It to indicate the format for encoding resized images.
+
+
+
JPEG - The JPEG encoding format
+
PNG - The PNG encoding format
+
+
+
SWFUpload.onload
+
onload is a function that will be executed by swfobject's addDOMLoadEvent. You can use onload to execute your script as soon as the page is ready. You should only use onload if you are not already using some other method (such as jQuery's Ready or Prototype's dom:loaded).
+ SWFUpload.onload = function () {
+ new SWFUpload(settingsObject);
+}
+
+
The above example will initialize SWFUpload using the browser's earliest load event. In most browsers this is the DOMReady event which often executes much sooner than the window.onload event.
+
+
Properties
+
+ The following list of properties is intended for your use as described below. Using other properties or
+ writing to read-only properties can cause SWFUpload to malfunction.
+
+
customSettings (read/write)
+
+ The customSettings property is an empty JavaScript object that can be used to store data associated with
+ an instance of SWFUpload. The customSettings object contents can be initialized using the custom_settings setting.
+
+
+
Example:
+ // Initialize SWFUpload with some custom settings
+var swfu = new SWFUpload({
+ custom_settings : {
+ custom_setting_1 : "custom_setting_value_1",
+ custom_setting_2 : "custom_setting_value_2",
+ custom_setting_n : "custom_setting_value_n",
+ }
+});
+
+swfu.customSettings.custom_setting_1 = "custom_setting_value_1"; // Change an existing custom setting
+swfu.customSettings.myNewCustomSetting = "new custom setting value"; // Add a new custom setting
+
+// Overwrite the customSettings with a completely new object
+swfu.customSettings = {
+ custom_setting_A : "custom_setting_value_A",
+ custom_setting_B : "custom_setting_value_B"
+};
+
+
+
The values stored in the customSettings object can then be easily accessed in the event handlers:
Contains the unique movie name of the SWFUpload instance. This value is passed to Flash and is used to facilitate Flash-to-JavaScript communication.
+ This value is used to index the instance in the SWFUpload.instances array. You should not change the movieName value.
+
+
Methods
+
The following methods are used to operate SWFUpload. Some are bound to DOM element click event handlers and others are used inside
+ SWFUpload event handlers.
Deprecated The addSetting function sets a setting value. If the value is undefined then the default_value is used. The function is used by SWFUpload
+ during initialization. Using addSetting to update a setting will not change the setting in the Flash Control.
+
addSetting returns the value that was stored in the setting.
+
+
object getSetting(setting_name)
+
Deprecated The getSetting function retrieves the value of a setting. If the setting is not found an empty string is returned.
Removed in v2.1.0 The retrieveSetting function is similar to the addSetting function except it does not modify the internal settings object. retrieveSetting
+ returns the setting_value unless it is undefined in which case it returns the default_value
+
This is a utility function.
+
+
bool destroy()
+
Added in v2.1.0
+
Removes the SWF DOM elements and then destroys SWFUpload internal references. Used for removing a SWFUpload instance from a page. It also attempts to prevent memory leaks in IE.
+
Returns true if the elements were removed successfully. Returns false if any error occurs leaving the SWFUpload instance in an inconsistent state.
+
+
void displayDebugInfo()
+
The displayDebugInfo outputs SWFUpload settings using the debug event. This function is automatically called after initialization if the debug setting is 'true'
+
+
void selectFile()
+
Deprecated. Not compatible with Flash Player 10.
+
selectFile causes the Flash Control to display a File Selection Dialog window. A single file may be selected from the Dialog window.
+
Calling selectFile begins the File Event Chain.
+
+
void selectFiles()
+
Deprecated. Not compatible with Flash Player 10.
+
selectFiles causes the Flash Control to display a File Selection Dialog window. A multiple files may be selected from the Dialog window.
+
Calling selectFiles begins the File Event Chain.
+
+
void startUpload(file_id)
+
startUpload causes the file specified by the file_id parameter to start the upload process. If the file_id parameter is omitted or undefined then the first file in the queue is uploaded.
+
+
Calling startUpload begins the Upload Event Chain.
startResizedUpload causes the file specified by the file_id parameter to start the upload process. SWFUpload attempts to resize the file (assuming it is an image format supported by Flash). If the image cannot be resized an uploadError occurs.
+
+
The width and height parameters specify the maximum size the resized image can be in each dimension. The other dimension is scaled to maintain the image aspect ratio.
+
+
The encoding parameter should be a value from the SWFUpload.RESIZE_ENCODING constants.
+
+
The quality parameter is used only for JPEG encoding and can be value from 0 to 100. The value is clamped if it is out of range.
+
+
The allowEnlarging parameter defines whether SWFUpload is allowed to enlarge the original image when resizing. If set to false the image is still re-encoded but will not be enlarged.
+
+
Calling startResizedUpload begins the normal Upload Event Chain. However, the Flash Player does not provide periodic uploadProgress events. SWFUpload sends only simulated 0% and 100% uploadProgress events.
+
+
A resized image is uploaded as POST value (rather than a FILE) due to security "features" introduced in Flash Player 10. Resized images have to be handled differently than normal uploads:
+
+ $resizedImageData = $_POST["Filedata"]; // Data from $_POST rather than $_FILE
+$fileHandle = fopen("image.jpg", "w");
+fwrite($fileHandle, $resizedImageData);
+fclose($fileHandle);
+
+
+
void cancelUpload(file_id, trigger_error_event)
+
+
cancelUpload cancels the file specified by the file_id parameter. The file is then removed from the queue.
+
If the file_id parameter is omitted or undefined then the first file in the queue is cancelled.
+
The trigger_error_event is optional. If set to false the uploadError event is suppressed.
+
+
void stopUpload()
+
+
stopUpload stops and re-queues the file currently being uploaded.
+
After the uploading file is stopped the uploadError event is fired. If no file is being uploaded then nothing happens and no event is fired.
+
+
bool requeueUpload(file_id or index)
+
+
requeueUpload requeues any previously queued file.
+
If the file cannot be found or is currently uploading false is returned.
+
+ Requeued files are not checked against the file size, queue size, file upload limit or any other settings but are simply added to the queue if a valid
+ reference to a file exists.
+
+
+
object getStats()
+
Retrieves the stats object.
+
+
void setStats(stats_object)
+
The Stats Object may be modified. This is useful if you wish to change the number of successful uploads or upload errors after an upload
+ has completed.
+
+
object getFile(file_id|index)
+
getFile is used to retrieve a File Object from the queue. The file retrieved by passing in a file id (the id property from a file object) or a file index (the index property from a file object).
+
When getting a file by file_id only files in the queue are available. If the file is not found null is returned.
+
When getting a file by index all queued (or files that generated a queue error) are available. If the index is out of range then null is returned
+
+
object getQueueFile(file_id|index)
+
getFile is used to retrieve a File Object from the upload queue. The file retrieved by passing in a file id (the id property from a file object) or a queue index (the position of the file in the queue). The index starts at zero.
+
When getting a file by file_id only files currently queued for upload are available. If the file is not found null is returned.
+
When getting a file by index only files currently queued for upload ar available. For example: getQueueFile(0) returns the file at front of the queue. This would be the next file uploaded when startUpload is called.
+
+
void addPostParam(name, value)
+
The addPostParam function adds a name/value pair that will be sent in the POST for all files uploaded.
+
The name/value pair will also appear in the post_params setting.
+
+
void removePostParam(name)
+
The removePostParam function removes a name/value pair from the values sent with the POST for file uploads.
+
The name/value pair is also be removed from the post_params setting.
+
+
bool addFileParam(file_id, name, value)
+
The addFileParam function adds a name/value pair that will be sent in the POST with the file specified by the file_id parameter.
+
The name/value pair will only be sent with the file it is added to. To send name/value pairs with all uploads use the post_param setting.
+
+
bool removeFileParam(file_id, name)
+
The removeFileParam function removes a name/value pair from a file upload that was added using addFileParam.
+
If the name/value pair was not found then 'false' is returned.
+
+
void setUploadURL(url)
+
Dynamically modifies the upload_url setting.
+
+
void setPostParams(param_object)
+
Dynamically modifies the post_params setting. Any previous values are over-written. The param_object should be a simple JavaScript object. All names and values must be strings.
+
+
void setFileTypes(types, description)
+
Dynamically updates the file_types and file_types_description settings. Both parameters are required.
+
+
void setFileSizeLimit(file_size_limit)
+
Dynamically modifies the file_size_limit setting. This applies to all future files that are queued. The file_size_limit parameter will accept a unit. Valid units are B, KB, MB, and GB. The default unit is KB.
Dynamically modifies the file_upload_limit setting. The special value zero (0) indicates "no limit".
+
+
void setFileQueueLimit(file_queue_limit)
+
Dynamically modifies the file_queue_limit setting. The special value zero (0) indicates "no limit".
+
+
void setFilePostName(file_post_name)
+
Dynamically modifies the file_post_name setting. The Linux Flash Player ignores this setting.
+
+
void setUseQueryString(use_query_string)
+
Dynamically modifies the use_query_string setting. When true this forces SWFUpload to send post parameters on the query string rather than in the post. The use_query_string parameter should be a boolean true or false.
+
+
void setDebugEnabled(debug_enabled)
+
Dynamically enables or disables debug output. The debug_enabled parameter should be a boolean true or false.
+
+
void setButtonImageURL(url)
+
Dynamically change the image used in the Flash Button. The image url must be relative to the swfupload.swf file, an absolute path (e.g., starting with a /), or
+ a fully qualified url (e.g., http://www.swfupload.org/buttonImage.png). Any image format supported by Flash can be loaded. The most notable formats are jpg, gif, and png.
+
+
The button image is expected to be a button sprite (or a single image file with several images stacked together). The image will be used to represent
+ all the button states by moving the image up or down to only display the needed portion. These states include: normal, hover, click, disabled. See the sample button images.
+
+
void setButtonDimensions(width, height)
+
Dynamically change the Flash button's width and height. The values should be numeric and should not include any units. The height value should
+ be 1/4th of the total button image height so the button state sprite images can be displayed correctly
+
+
void setButtonText(text)
+
Sets the text that should be displayed over the Flash button. Text that is too large and overflows the button size will be clipped.
+
The text can be styled using HTML supported by the Flash Player (Adobe Documentation)
+
+
void setButtonTextStyle(css_style_text)
+
Sets the CSS styles used to style the Flash Button Text. CSS should be formatted according to the Flash Player documentation (Adobe Documentation)
+
Style classes defined here can then be referenced by HTML in the button_text setting.
+
+
void setButtonTextPadding(left, top)
+
Sets the top and left padding of the Flash button text. The values may be negative.
+
+
void setButtonDisabled(isDisabled)
+
When 'true' changes the Flash Button state to disabled and the BUTTON_ACTION is ignored. The mouseClick event is always fired when the button is disabled.
+
+
void setButtonAction(buttonAction)
+
Sets the action taken when the Flash button is clicked. Valid action values are taken from the BUTTON_ACTION constants.
+
+
void setButtonCursor(buttonCursor)
+
Sets the mouse cursor shown when hovering over the Flash button. Valid cursor values are taken from the CURSOR constants.
+
+
+
+
Events
+
SWFUpload fires various events during its operation. These events can be handled by the developer to update the UI, change behavior, or report errors.
+
All SWFUpload events are called in the context of a SWFUpload instance. This means that the 'this' object refers to the SWFUpload instance that
+ fired the event.
+
+
SWFUpload events should be set only by assigning the event handler function in the settings object during object initialization. You should not override the
+ internal functions belonging to the SWFUpload.prototype object.
+
+
During a file upload events are usually called in this order (the Upload Event Chain):
+
+
uploadResizeStart
+
uploadStart
+
uploadProgress (called over and over again as the file uploads)
+
uploadError (called if some kind of error occurs, the file is canceled or stopped)
+
uploadSuccess (the upload finished successfully, data returned from the server is available)
+
uploadComplete (the upload is complete and SWFUpload is ready to start the next file)
+
+
+
flashReady()
+
flashReady is an internal event that should not be overwritten. It is called by the Flash Control to notify SWFUpload that the Flash
+ movie has loaded and is ready to accept commands.
+
+
swfUploadPreload()
+
+ The swfUploadPreload event is fired after SWFUpload has determined what features are available but before the Flash Movie is loaded. Returning false from this event prevents SWFUpload from loading.
+ This event can be used to gracefully degrade if the client's browser does not support the features needed.
+
+
Set using the swfupload_preload_handler setting.
+
+
swfUploadLoadFailed()
+
The xxxxxx event is fired if SWFUpload determines it cannot load or an exception occurs while added the Flash Movie to the document. SWFUpload may not be able to load because the Flash Player is not installed or a version older than 9.0.28 is installed
+
Set using the swfupload_load_failed_handler setting.
+
+
swfUploadLoaded()
+
The swfUploadLoaded event is fired by flashReady. It is settable. swfUploadLoaded is called to let you know that it is safe to call SWFUpload methods.
+
Set using the swfupload_loaded_handler setting.
+
+
mouseClick()
+
mouseClick is fired when the button is clicked and the button_action setting is set to SWFUpload.BUTTON_ACTION.NONE or the button is disabled. This event is not fired for other button_action settings and the button is enabled.
+
Set using the mouse_click_handler setting.
+
+
mouseOver()
+
mouseOver is fired when the cursor moves over any part of the Flash Movie.
+
Set using the mouse_over_handler setting.
+
+
mouseOut()
+
mouseOut is fired when the cursor moves off the Flash Movie.
+
Set using the mouse_out_handler setting.
+
+
fileDialogStart()
+
fileDialogStart is fired after selectFile for selectFiles is called. This event is fired immediately before the File Selection Dialog
+ window is displayed. However, the event may not execute until after the Dialog window is closed.
+
Set using the file_dialog_start_handler setting.
+
+
fileQueued(file object)
+
The fileQueued event is fired for each file that is queued after the File Selection Dialog window is closed.
+
Set using the file_queued_handler setting.
+
+
fileQueueError(file object, error code, message)
+
The fileQueueError event is fired for each file that was not queued after the File Selection Dialog window is closed. A file may not be queued
+ for several reasons such as, the file exceeds the file size, the file is empty or a file or queue limit has been exceeded.
+
The cause of the queue error is specified by the error code parameter. The error code corresponds to a SWFUpload.QUEUE_ERROR constant.
+
Set using the file_queue_error_handler setting.
+
+
fileDialogComplete(number of files selected, number of files queued, total number of files in the queued)
+
The fileDialogComplete event fires after the File Selection Dialog window has been closed and all the selected files have been processed. The 'number of files queued' argument indicates the number of files that were queued from the dialog selection (as opposed to the number of files in the queue).
+
If you want file uploading to begin automatically this is a good place to call 'this.startUpload()'
+
Set using the file_dialog_complete_handler setting.
uploadResizeStart is called immediately before an image is resized. Resizing does not provide any progress events but can take some time due to re-encoding of the file. If an error occurs during resizing the uploadError event is fired.
+
+
When resizing is complete SWFUpload moves on to the uploadStart event and continues using the normal event chain.
+
+
uploadStart(file object)
+
uploadStart is called immediately before the file is uploaded. This event provides an opportunity to perform any last minute validation, add post
+ params or do any other work before the file is uploaded.
+
+
The upload can be cancelled by returning 'false' from uploadStart. If you return 'true' or do not return any value then the upload proceeds. Returning
+ 'false' will cause an uploadError event to fired.
+
+
Set using the upload_start_handler setting.
+
+
uploadProgress(file object, bytes complete, total bytes)
+
The uploadProgress event is fired periodically by the Flash Control. This event is useful for providing UI updates on the page.
+
Note: The Linux Flash Player fires a single uploadProgress event after the entire file has been uploaded. This is a bug in
+ the Linux Flash Player that we cannot work around.
+
Set using the upload_progress_handler setting.
+
+
uploadError(file object, error code, message)
+
The uploadError event is fired any time an upload is interrupted or does not complete successfully. The error code parameter indicates the type of error
+ that occurred. The error code parameter specifies a constant in SWFUpload.UPLOAD_ERROR.
+
Stopping, Cancelling or returning 'false' from uploadStart will cause uploadError to fire. Upload error will not fire for files that are cancelled
+ but still waiting in the queue.
+
Set using the upload_error_handler setting.
+
+
uploadSuccess(file object, server data, received response)
+
uploadSuccess is fired when the entire upload has been transmitted and the server returns a HTTP 200 status code. Any data outputted by the server is available
+ in the server data parameter.
+
+
+ Due to some bugs in the Flash Player the server response may not be acknowledged and no uploadSuccess event is fired by Flash. In this case the
+ assume_success_timeout setting is checked to see if enough time has passed to fire uploadSuccess anyway. In this case the received response parameter will be false.
+
+
+
+ The http_success setting allows uploadSuccess to be fired for HTTP status codes other than 200. In this case no server data is available from the Flash Player.
+
+
+
At this point the upload is not yet complete. Another upload cannot be started from uploadSuccess.
+
+
Set using the upload_success_handler setting.
+
+
uploadComplete(file object)
+
uploadComplete is always fired at the end of an upload cycle (after uploadError or uploadSuccess). At this point the upload is complete and
+ another upload can be started.
+
If you want the next upload to start automatically this is a good place to call this.uploadStart(). Use caution when calling uploadStart inside
+ the uploadComplete event if you also have code that cancels all the uploads in a queue.
+
Set using the upload_complete_handler setting.
+
+
debug(message)
+
The debug event is called by the SWFUpload library and the Flash Control when the debug setting is set to 'true'. If the debug
+ event is not overridden then SWFUpload writes debug messages to the SWFUpload console (a text box dynamically added to the end of the page body).
+
Set using the debug_handler setting.
+
+
SWFUpload Utility Objects
+
Settings object
+
The settings object is a JavaScript object that provides the settings for the SWFUpload instance. Each setting should only appear once. Many settings
+ are optional and provide suitable default values if omitted. See the setting details for required and optional settings.
The upload_url setting accepts a full, absolute, or relative target URL for the uploaded file. Relative URLs should be relative to document. The upload_url should be in the same domain as the Flash Control for best compatibility.
+
If the preserve_relative_urls setting is false SWFUpload will convert the relative URL to an absolute URL to avoid the URL being interpreted differently by the Flash Player on different platforms. If you disable SWFUploads conversion of the URL relative URLs should be relative to the swfupload.swf file.
+
+
file_post_name
+
The file_post_name allows you to set the value name used to post the file. This is not related to the file name.
+ The default value is 'Filedata'. For maximum compatibility it is recommended that the default value is used.
+
+
post_params
+
+ The post_params setting defines the name/value pairs that will be posted with each uploaded file. This setting accepts a simple JavaScript object.
+ Multiple post name/value pairs should be defined as demonstrated in the sample settings object. Values must be either strings or numbers (as interpreted by the JavaScript typeof function).
+
+
Note: Flash Player 8 does not support sending additional post parameters. SWFUpload will automatically send the post_params as part of the query string.
+
+
use_query_string
+
+ The use_query_string setting may be true or false. This value indicates whether SWFUpload should send the post_params and file params on the query string or the post. This setting was introduced in SWFUpload v2.1.0.
+
+
+
preserve_relative_urls
+
A boolean value that indicates whether SWFUpload should attempt to convert relative URLs used by the Flash Player to absolute URLs. If set to true SWFUpload will not modify any URLs. The default value is false.
+
+
requeue_on_error
+
+ The requeue_on_error setting may be true or false. When this setting is true any files that has an
+ uploadError (excluding fileQueue errors and the FILE_CANCELLED uploadError) is returned to the front of
+ the queue rather than being discarded. The file can be uploaded again if needed. To remove the file from the
+ queue the cancelUpload method must be called.
+
+
+ All the events associated with a failed upload are still called and so the requeuing the failed upload can conflict
+ with the Queue Plugin (or custom code that uploads the entire queue). Code that automatically uploads the next file
+ in the queue will upload the failed file over and over again if care is not taken to allow the failing upload to be
+ cancelled.
+
+
+ This setting was introduced in SWFUpload v2.1.0.
+
+
+
http_success
+
+ An array that defines the HTTP Status Codes that will trigger success. 200 is always a success. Also, only the 200 status code provides the serverData.
+
+
+ When returning and accepting an HTTP Status Code other than 200 it is not necessary for the server to return content.
+
+
+
assume_success_timeout
+
+ The number of seconds SWFUpload should wait for Flash to detect the server's response after the file has finished uploading. This setting allows you to
+ work around the Flash Player bugs where long running server side scripts causes Flash to ignore the server response or the Mac Flash Player bug that ignores
+ server responses with no content.
+
+
+ Testing has shown that Flash will ignore server responses that take longer than 30 seconds after the last uploadProgress event.
+
+
+ A timeout of zero (0) seconds disables this feature and is the default value. SWFUpload will wait indefinitely for the Flash Player to trigger the uploadSuccess event.
+
+
+
file_types
+
+ The file_types setting accepts a semi-colon separated list of file extensions that are allowed to be selected by the user. Use '*.*' to allow all file types.
+
+
+
file_types_description
+
+ A text description that is displayed to the user in the File Browser dialog.
+
+
+
file_size_limit
+
+ The file_size_limit setting defines the maximum allowed size of a file to be uploaded. This setting accepts a value and unit.
+ Valid units are B, KB, MB and GB. If the unit is omitted default is KB. A value of 0 (zero) is interpreted as unlimited.
+
+
+ Note: This setting only applies to the user's browser. It does not affect any settings or limits on the web server.
+
+
+
file_upload_limit
+
+ Defines the number of files allowed to be uploaded by SWFUpload. This setting also sets the upper bound of the file_queue_limit
+ setting. Once the user has uploaded or queued the maximum number of files she will no longer be able to queue additional files. The
+ value of 0 (zero) is interpreted as unlimited. Only successful uploads (uploads the trigger the uploadSuccess event) are counted
+ toward the upload limit. The setStats function can be used to modify the number of successful uploads.
+
+
Note: This value is not tracked across pages and is reset when a page is refreshed. File quotas should be managed by the web server.
+
+
file_queue_limit
+
+ Defines the number of unprocessed files allowed to be simultaneously queued. Once a file is uploaded, errored, or cancelled a new
+ files can be queued in its place until the queue limit has been reached. If the upload limit (or remaining uploads allowed) is less
+ than the queue limit then the lower number is used.
+
+
+
flash_url
+
+ The full, absolute, or relative URL to the Flash Control swf file. This setting cannot be changed once the SWFUpload has been
+ instantiated. Relative URLs are relative to the page URL.
+
+
+
flash9_url
+
+ (Added in v2.5.0) the full, absolute, or relative URL to the Flash Control swf file that supports Flash Player 9.
+
+
+
flash_width
+
+ (Removed in v2.1.0) Defines the width of the HTML element that contains the flash. Some browsers do not function correctly if this setting is less than 1 px.
+ This setting is optional and has a default value of 1px.
+
+
+
flash_height
+
+ (Removed in v2.1.0) Defines the height of the HTML element that contains the flash. Some browsers do not function correctly if this setting is less than 1 px.
+ This setting is optional and has a default value of 1px.
+
+
+
flash_color
+
+ Removed in v2.2.0 This setting sets the background color of the HTML element that contains the flash. The default value is '#FFFFFF'.
+
+
+ Note: This setting may not be effective in "skinning" 1px flash element in all browsers.
+
+
+
prevent_swf_caching
+
+ Added in v2.2.0 This boolean setting indicates whether a random value should be added to the Flash URL in an attempt to
+ prevent the browser from caching the SWF movie. This works around a bug in some IE-engine based browsers.
+
+
Note: The algorithm for adding the random number to the URL is dumb and cannot handle URLs that already have some parameters.
+
+
debug
+
A boolean value that defines whether the debug event handler should be fired.
+
+
button_placeholder_id
+
(Added in v2.2.0) This required setting sets the ID of DOM element that will be replaced by the Flash Button. This setting overrides the button_placeholder setting. The Flash button can be styled using the CSS class 'swfupload'.
+
+
button_placeholder
+
(Added in v2.2.0) This required setting sets the DOM element that will be replaced by the Flash Button. This setting is only applied if the button_placeholder_id is not set. The Flash button can be styled using the CSS class 'swfupload'.
+
+
button_image_url
+
(Added in v2.2.0) Fully qualified, absolute or relative URL to the image file to be used as the Flash button. Any Flash supported image file format can be used (another SWF file or gif, jpg, or png).
+
This URL is affected by the preserve_relative_urls setting and should follow the same rules as the upload_url setting.
+
+
The button image is treated as a sprite. There are 4 button states that must be represented by the button image. Each button state image
+ should be stacked above the other in this order: normal, hover, down/click, disabled.
+
+
button_width
+
(Added in v2.2.0) A number defining the width of the Flash button.
+
+
button_height
+
(Added in v2.2.0) A number defining the height of the Flash button. This value should be 1/4th of the height or
+ the button image.
+
+
button_text
+
(Added in v2.2.0) Plain or HTML text that is displayed over the Flash button. HTML text can be further styled using CSS
+ classes and the button_text_style setting. See Adobe's Flash documentation for details.
+
+
button_text_style
+
(Added in v2.2.0) CSS style string that defines how the button_text is displayed.
+ See Adobe's Flash documentation for details.
+
+
button_text_top_padding
+
(Added in v2.2.0) Used to vertically position the Flash button text. Negative values may be used.
+
+
button_text_left_padding
+
(Added in v2.2.0) Used to horizontally position the Flash button text. Negative values may be used.
+
+
button_action
+
(Added in v2.2.0) Defines the action taken when the Flash button is clicked. Valid action values can be found in the swfupload.js file under the BUTTON_ACTION object.
+
+
button_disabled
+
(Added in v2.2.0) A boolean value that sets whether the Flash button is in the disabled state. When in the disabled state the button will not execute any actions.
+
+
button_cursor
+
(Added in v2.2.0) Used to define what type of mouse cursor is displayed when hovering over the Flash button.
+
+
button_window_mode
+
(Added in v2.2.0) Sets the WMODE property of the Flash Movie. Valid values are available in the SWFUpload.WINDOW_MODE constants.
+
+
custom_settings
+
+ The custom_settings setting allows developers to safely attach additional information to a SWFUpload instance without
+ worrying about affecting internal SWFUpload values or changes in new SWFUpload versions. This setting accepts a JavaScript
+ object.
+
+
+ Once instantiated the custom settings are accessed in the 'customSettings' property of the SWFUpload instance.
+
+ var swfu = new SWFUpload({
+ custom_settings : {
+ "My Setting" : "This is my setting",
+ myothersetting : "This is my other setting",
+ integer_setting : 100,
+ a_dom_setting : document.getElementById("some_element_id")
+ }
+});
+
+var my_setting = swfu.customSettings["My Setting"]);
+swfu.customSettings["My Setting"] = "This is my new setting";
+swfu.customSetting.myothersetting = "another new value";
+swfu.customSetting.integer_setting += 25;
+swfu.customSetting["a_dom_setting"].style.visibility = "hidden";
+
+
Event Handlers
+
+ The remaining settings define the event handlers called by SWFUpload during its operation. JavaScript functions should
+ be defined to handle these events as needed.
+
+
+
+
Support Object
+
The support object is a property of a SWFUpload instance and identifies what features SWFUpload can support based on the Flash Player version installed in the client browser.
+ {
+ load : bool, // Indicates if SWFupload is able to load based of Flash Player version
+ imageResize : bool, // Indicates of Flash Player 10 or later is installed and SWFUpload supports client side resizing and uploading of images.
+}
+
+
File Object
+
The file object is passed to several event handlers. It contains information about the file. Some operating systems do not fill in all the values (this
+ is especially true for the createdate and modificationdate values).
+ {
+ id : string, // SWFUpload file id, used for starting or cancelling and upload
+ index : number, // The index of this file for use in getFile(i)
+ name : string, // The file name. The path is not included.
+ size : number, // The file size in bytes
+ type : string, // The file type as reported by the client operating system
+ creationdate : Date, // The date the file was created
+ modificationdate : Date, // The date the file was last modified
+ filestatus : number, // The file's current status. Use SWFUpload.FILE_STATUS to interpret the value.
+ post : object // The post params that will be sent with this file (compiled from the post_params setting and any params added with the addFileParam function
+
+}
+
+
Stats Object
+
The Stats object provides information about the upload queue.
+
That stats object contains the following properties:
+ {
+ in_progress : number // 1 or 0 indicating if a file upload is currently in progress
+ files_queued : number // The number of files currently in the queue
+ successful_uploads : number // The number of files that have uploaded successfully (caused uploadSuccess to be fired)
+ upload_errors : number // The number of files that have had errors (excluding cancelled files)
+ upload_cancelled : number // The number of files that have been cancelled
+ queue_errors : number // The number of files that caused fileQueueError to be fired
+}
+
All these values can be updated using setStats() except the in_progress and files_queued values.
+
+
SWFUpload Plug-ins
+
+
With SWFUpload v2.0 several plugins have been introduced. They are provided to help with common tasks associated with implementing SWFUpload.
+
Currently most of the documentation for using the plugins is contained in the plugin JavaScript file.
+
+
SWFObject
+
+ The SWFObject plugin uses the SWFObject library to handle the embedding
+ of the SWFUpload Flash Component into the page.
+
+
+ This plugin also provides support for Document Ready loading and Flash Version Detection. Usage details are documented
+ in the plugin file itself. You should not use the SWFObject's Document Ready loading mixed with another libraries DOMReady. Use
+ one or the other but not both.
+
+
+
Flash Player 10: Because Flash Player 10 requires the SWFUpload swf to act is a button the movie must be visible in order
+ for it to load. If the button_placeholder_id is set to an element that is hidden (visibility set to hidden or display set to none) SWFUpload will
+ fail to load.
+
+
Cookies
+
In response to the Flash Cookie Bug the Cookies Plugin automatically retrieves your browser's cookies and sends them
+ with the upload. The are sent as POST or GET variables to the upload url.
+
+
Note that this plugin sends the cookies name/values in the POST or GET. On the server side they will not be accessible as cookies. Some frameworks that
+ automatically check cookies for session or authentication values still will not be able to find the values.
+
+
Queue Handling
+
This plugin provides Queue Handling features such as entire queue uploading, entire queue cancelling and automatic starting of uploads after being queued.
+
+
+
Speed
+
This Plugin extends the 'file' object with several properties that describe the current upload. This includes current speed, average speed, elapsed time, remaining time and more.
+
+
+
Known Issues
+
The Flash Player and many Browsers have bugs that have a direct impact on the performance of SWFUpload. While we have worked
+ hard to get around many issues but there are some things that we cannot fix.
+
+
Cancelling in Linux
+
Older Flash 9 Players for Linux cause the browser to crash if an upload is cancelled. Newer Flash 9 Players behave better.
+
+
Upload Progress in Linux
+
The Flash Player in Linux sends a single uploadProgress event after the file has finished uploading.
+
In some distributions the entire browser locks up while the upload is in progress.
+
+
Upload Progress in OS X
+
There have been some reports that uploadProgress events are not fired in MAC Flash Players. The specifics haven't been pinned down but be aware of the possible issue.
+
+
MIME Type
+
The Flash Player uploads all files with a mime type of application/octet-stream regardless of the file's actual mime type.
+
+
Maximum number of selected files
+
The Flash Player does not impose a maximum number of selected files. However, it builds a selected files string which does have a maximum length.
+ The string is built using the file's name and the separator [quote][space][quote]. The total number of files selected is determined by the sum
+ of the lengths of the file names and a prefixed and postfixed [quote] character (2 characters) and the number of files selected minus one times 3 (for the separator string)
+
+
This limitation may vary from system to system. If a user selects too many files they will be receive a Flash Player generated warning message and will
+ be left at the File Selection Dialog.
+
+
Proxies
+
The Flash Player may not properly use proxies. It does not handle authenticating proxies well (if at all) and will some-times crash.
+
Some anti-virus software uses a proxy to scan uploads and cause SWFUpload to believe the entire file has been uploaded. SWFUpload will fire uploadProgress events very quickly
+ until it reaches 100% and will then seem to pause until the proxy completes uploading the file to the server.
+
Kaspersky Anti-Virus: Kaspersky (and other) Anti-Virus suites implement a client-side proxy that intercepts and scans outgoing data. SWFUpload
+ cannot detect the presence of proxy servers. These types of proxy servers accept the entire upload very quickly and they wait while the data is scanned and transmitted
+ to the original destination. The Flash Player times out the connection (because of appearent inactivity) and returns a #2038 error. SWFUpload fires an uploadError event.
+
+
Apache mod_security
+
Apache's mod_security validates POST to the server. Flash Player has implemented an edge case (there is argument as to whether it is invalid or note)
+ POST for file uploads and so servers implementing
+ mod_security will reject the upload. mod_security can be disabled using your .htaccess file
+
+
SSL
+
There have been some reports that the Flash Player cannot upload through SSL.
+ The issue has not been pinned down but uploading over SSL may be unreliable. There especially seems to be an issue with
+ using self-signed certificates.
+
Also, SSL tickets from untrusted Certificate Authorities (CA) do not work as Flash does not provide a method for accepting the certificate. It has been noted that, like the cookie bug,
+ that Flash Player on Windows obtains its trusted CA list from Internet Explorer regardless of the browser in use.
+
+
Authentication
+
HTTP Authentication is not well supported by the Flash Player. Later versions of Flash Player behave better. Old version of Flash Player would crash the browser.
+
+
Prematurely terminated connections
+
Prematurely ending the response (such as a Response.end() in ASP.Net) can sometimes cause successful uploads to be reported as failed.
+
+
Filedata POST name in Linux
+
Changing the Filedata value (file_post_name setting) is ignored in Linux Flash Players.
+
+
Cookie bug
+
On Windows the Non-IE Flash Player plugin (FireFox, Opera, Safari, etc) will send the IE cookies regardless of the browser used. This breaks authentication and sessions for many server-side scripting technologies.
+
Developers should manually pass Session and Authentication cookie information and manually restore Sessions on the Server Side if they wish to use Sessions
+
The SWFUpload package contains work-around sample code for PHP and ASP.Net
+
+
ExternalInterface bugs
+
Flash Player does not properly escape data when communication with the browser/JavaScript. SWFUpload goes to great lengths to work-around this issue. If this
+ bug is fixed in future Flash Players/Browsers then SWFUpload will send extra escaped data.
+
+
Server Data length bugs
+
Very long server data is corrupted on Mac and Linux Flash Players. Server data will be truncated, garbled, and/or repeated. We recommend
+ keeping data returned from the server short and concise.
+
+
Avant Browser
+
For some users the Avant Browser does not work with SWFUpload after the Flash Control has been cached. This has been reproduced by the
+ SWFUpload developers but the Avant Browser developers did not experience any problems.
+
When the page is reloaded SWFUpload loads and fires the swfupload_loaded event. However, none of the ExternalInterface callback functions are defined
+ on the movie element. SWFUpload v2.0.2 has added checks which prevent swfupload_loaded from firing if the callback functions are not detected.
+
+
SWFUpload v2.2.0 added the prevent_swf_caching setting that attempts to work around this issue.
+
+
File Dialog & Page Changing
+
Leaving or reloading the current page while the File Browser Dialog window is open will cause the browser to crash (all browsers, all OSs). Most commonly this is caused by failing to
+ cancel a click event on an <a> tag where the onclick event calls the selectFile or selectFiles function.
+
+
Long Running Upload Scripts
+
After Flash has uploaded the file to the webserver the upload script is executed. This script handles the file whether that means saving it, creating a thumbnail, scanning for viruses, etc.
+ If the upload script does not return any data within 30 seconds Flash will disconnect and return an IO Error. You can prevent this by returning characters or data while
+ the script runs (if possible). For PHP, the script continues to run and complete successfully even though Flash has terminated the connection. Any data returned
+ by the script after Flash has disconnected is lost.
+
+
WMODE / BUTTON_WINDOW_MODE
+
+
In some browsers the selected WMODE (which is set using the BUTTON_WINDOW_MODE) can prevent the Flash Control from loading
+ if the control is not on screen. The control will finally load once the user scrolls the page so the control becomes visible.
+
+
This behavior can adversely affect the SWFObject plugin. No SWFUpload events will be fire and the button image will not be
+ loaded until the control becomes visible.
+
+
On some systems (Linux is affected) when the WMODE is transparent Flash opens the File Dialog window behind the browser window.
+
+
Memory Leaks
+
Some browsers (especially IE) cannot recover memory used by the Flash Player when JavaScript communication via the ExternalInterface classes is used (like in SWFUpload).
+ Creating many SWFUpload instances and/or reloading the page several times will cause the browser to consume more and more memory until it crashes or otherwise harms the
+ system.
+
+
In v2.2.0 SWFUpload we have implemented some preventative measures. Some of these measures are pro-active but it is still recommended that you
+ call the destroy method when the page unloads. If you are using hundreds of SWFUpload instances on a page you should use caution and test
+ carefully for memory leaks.
+
+
Other Mac Issues
+
+
+ Content must be returned by the server or the Mac Flash Player will not trigger the uploadSuccess event. We have added the assume_success_timeout setting to help work around this.
+ But in general it is simply easier and more reliable to return a short string after the upload is complete.
+
+
+ Users have reported that uploading to subdomains does not work with the Mac Flash Player.
+
+
+ Users have reported that pages that redirect (HTTP Status 302) are not handled by the Mac Flash Player. Windows
+ clients seem to handle this issue. 302 redirects are used in many authentication schemes and MVC frameworks.
+
+
+ The flash documentation states that on OS early than OS X 10.3 the bytes loaded is always reported as -1. SWFUpload converts
+ this to 0 but the total bytes will never be sent and 100% won't be reached. The UI should be updated to display 100% complete in
+ uploadSuccess or uploadComplete events to maintain a consistent UI.
+
+
+ Some users have reported issues if there is a space character in the upload_url for the Mac Flash Player. Avoid spaces or try replacing them with + or %20.
+
+
+ Users have reported that the Flash Player for Mac adds the PORT to the HTTP HOST header (e.g., http://www.example.com:80). If you are
+ checking this variable in your server-side script be aware of the possible issue.
+
+
+ Files that contain only a resource fork are treated as zero byte file by the Flash Player and cannot be uploaded. (Note: Flash Player 10.1 may resolve this issue)
+
+
+
+
+
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/plugins/SWFObject License.txt b/media_tree/static/media_tree/lib/swfupload/plugins/SWFObject License.txt
new file mode 100644
index 0000000..189d009
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/plugins/SWFObject License.txt
@@ -0,0 +1,4 @@
+/* SWFObject v2.0 rc4
+ Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis
+ This software is released under the MIT License
+*/
diff --git a/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.cookies.js b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.cookies.js
new file mode 100644
index 0000000..9c83c35
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.cookies.js
@@ -0,0 +1,53 @@
+/*
+ Cookie Plug-in
+
+ This plug in automatically gets all the cookies for this site and adds them to the post_params.
+ Cookies are loaded only on initialization. The refreshCookies function can be called to update the post_params.
+ The cookies will override any other post params with the same name.
+*/
+
+var SWFUpload;
+if (typeof(SWFUpload) === "function") {
+ SWFUpload.prototype.initSettings = function (oldInitSettings) {
+ return function (userSettings) {
+ if (typeof(oldInitSettings) === "function") {
+ oldInitSettings.call(this, userSettings);
+ }
+
+ this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point
+ };
+ }(SWFUpload.prototype.initSettings);
+
+ // refreshes the post_params and updates SWFUpload. The sendToFlash parameters is optional and defaults to True
+ SWFUpload.prototype.refreshCookies = function (sendToFlash) {
+ if (sendToFlash === undefined) {
+ sendToFlash = true;
+ }
+ sendToFlash = !!sendToFlash;
+
+ // Get the post_params object
+ var postParams = this.settings.post_params;
+
+ // Get the cookies
+ var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;
+ for (i = 0; i < caLength; i++) {
+ c = cookieArray[i];
+
+ // Left Trim spaces
+ while (c.charAt(0) === " ") {
+ c = c.substring(1, c.length);
+ }
+ eqIndex = c.indexOf("=");
+ if (eqIndex > 0) {
+ name = c.substring(0, eqIndex);
+ value = c.substring(eqIndex + 1);
+ postParams[name] = value;
+ }
+ }
+
+ if (sendToFlash) {
+ this.setPostParams(postParams);
+ }
+ };
+
+}
diff --git a/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.proxy.js b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.proxy.js
new file mode 100644
index 0000000..00f82c6
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.proxy.js
@@ -0,0 +1,96 @@
+/*
+ Proxy Plug-in
+
+ Features:
+ Times an upload to see if it appear suspiciously fast which might indicate a proxy server or anti-virus suite intercepting the upload.
+ If the upload seems too fast an uploadError event is fired with PROXY error code after the final uploadProgress event.
+
+ Adds a SWFUpload setting allowing you to tweak the bytes/s for triggering the error:
+ proxy_detect_threshold : 256000
+
+ Adds an UPLOAD_ERROR entry called PROXY:
+ function uploadError(file, errorCode, message) {
+ if (errorCode === SWFUpload.UPLOAD_ERROR.PROXY) {
+ alert("You might have a proxy!");
+ }
+ }
+ */
+
+var SWFUpload;
+if (typeof(SWFUpload) === "function") {
+ SWFUpload.proxyDetect = {};
+ SWFUpload.UPLOAD_ERROR.PROXY = -30300;
+
+ SWFUpload.prototype.initSettings = (function (oldInitSettings) {
+ return function (userSettings) {
+ if (typeof(oldInitSettings) === "function") {
+ oldInitSettings.call(this, userSettings);
+ }
+
+ this.ensureDefault = function (settingName, defaultValue) {
+ this.settings[settingName] = (userSettings[settingName] == undefined) ? defaultValue : userSettings[settingName];
+ };
+
+ // List used to keep the speed stats for the files we are tracking
+ this.proxyDetectFileStartTimes = {};
+ this.proxyDetectSettings = {};
+
+ this.ensureDefault("proxy_detect_threshold", 256000); // Default is 250 KB per second
+
+ this.proxyDetectSettings.user_upload_progress_handler = this.settings.upload_progress_handler;
+ this.proxyDetectSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
+
+ this.settings.upload_progress_handler = SWFUpload.proxyDetect.uploadProgressHandler;
+ this.settings.upload_complete_handler = SWFUpload.proxyDetect.uploadCompleteHandler;
+
+
+ delete this.ensureDefault;
+ };
+ }(SWFUpload.prototype.initSettings));
+
+ SWFUpload.proxyDetect.uploadProgressHandler = function (file, bytesComplete, bytesTotal) {
+ var ex1 = null, time, differenceMS, bps;
+ try {
+ if (typeof this.proxyDetectSettings.user_upload_progress_handler === "function") {
+ this.proxyDetectSettings.user_upload_progress_handler.call(this, file, bytesComplete, bytesTotal);
+ }
+ } catch (ex1) { }
+
+
+ if (bytesComplete === 0) {
+ this.proxyDetectFileStartTimes[file.ID] = new Date();
+
+ } else if (bytesComplete === bytesTotal) {
+ try {
+ // Calculate the Bps and decide if we should trigger the error
+ time = new Date();
+ differenceMS = time.getTime() - this.proxyDetectFileStartTimes[file.ID].getTime();
+
+ if (differenceMS === 0) {
+ differenceMS = 1;
+ }
+
+ bps = bytesTotal / (differenceMS * 1000);
+ if (bps > parseInt(this.settings.proxy_detect_threshold, 10)) {
+ this.queueEvent("upload_error_handler", [file, SWFUpload.UPLOAD_ERROR.PROXY, bps]);
+ }
+ } catch (ex) {
+ }
+ }
+
+ if (ex1 !== null) {
+ throw(ex1);
+ }
+ };
+
+ SWFUpload.proxyDetect.uploadCompleteHandler = function (file) {
+ try {
+ delete this.proxyDetectFileStartTimes[file.ID];
+ } catch (ex) {
+ }
+
+ if (typeof this.proxyDetectSettings.user_upload_progress_handler === "function") {
+ return this.proxyDetectSettings.user_upload_progress_handler.call(this, file);
+ }
+ };
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.queue.js b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.queue.js
new file mode 100644
index 0000000..a712fcb
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.queue.js
@@ -0,0 +1,98 @@
+/*
+ Queue Plug-in
+
+ Features:
+ *Adds a cancelQueue() method for cancelling the entire queue.
+ *All queued files are uploaded when startUpload() is called.
+ *If false is returned from uploadComplete then the queue upload is stopped.
+ If false is not returned (strict comparison) then the queue upload is continued.
+ *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
+ Set the event handler with the queue_complete_handler setting.
+
+ */
+
+var SWFUpload;
+if (typeof(SWFUpload) === "function") {
+ SWFUpload.queue = {};
+
+ SWFUpload.prototype.initSettings = (function (oldInitSettings) {
+ return function (userSettings) {
+ if (typeof(oldInitSettings) === "function") {
+ oldInitSettings.call(this, userSettings);
+ }
+
+ this.queueSettings = {};
+
+ this.queueSettings.queue_cancelled_flag = false;
+ this.queueSettings.queue_upload_count = 0;
+
+ this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
+ this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
+ this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
+ this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
+
+ this.settings.queue_complete_handler = userSettings.queue_complete_handler || null;
+ };
+ })(SWFUpload.prototype.initSettings);
+
+ SWFUpload.prototype.startUpload = function (fileID) {
+ this.queueSettings.queue_cancelled_flag = false;
+ this.callFlash("StartUpload", [fileID]);
+ };
+
+ SWFUpload.prototype.cancelQueue = function () {
+ this.queueSettings.queue_cancelled_flag = true;
+ this.stopUpload();
+
+ var stats = this.getStats();
+ while (stats.files_queued > 0) {
+ this.cancelUpload();
+ stats = this.getStats();
+ }
+ };
+
+ SWFUpload.queue.uploadStartHandler = function (file) {
+ var returnValue;
+ if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
+ returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
+ }
+
+ // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
+ returnValue = (returnValue === false) ? false : true;
+
+ this.queueSettings.queue_cancelled_flag = !returnValue;
+
+ return returnValue;
+ };
+
+ SWFUpload.queue.uploadCompleteHandler = function (file) {
+ var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
+ var continueUpload;
+
+ if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
+ this.queueSettings.queue_upload_count++;
+ }
+
+ if (typeof(user_upload_complete_handler) === "function") {
+ continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
+ } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
+ // If the file was stopped and re-queued don't restart the upload
+ continueUpload = false;
+ } else {
+ continueUpload = true;
+ }
+
+ if (continueUpload) {
+ var stats = this.getStats();
+ if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
+ this.startUpload();
+ } else if (this.queueSettings.queue_cancelled_flag === false) {
+ this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
+ this.queueSettings.queue_upload_count = 0;
+ } else {
+ this.queueSettings.queue_cancelled_flag = false;
+ this.queueSettings.queue_upload_count = 0;
+ }
+ }
+ };
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.speed.js b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.speed.js
new file mode 100644
index 0000000..4d96ffb
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/plugins/swfupload.speed.js
@@ -0,0 +1,346 @@
+/*
+ Speed Plug-in
+
+ Features:
+ *Adds several properties to the 'file' object indicated upload speed, time left, upload time, etc.
+ - currentSpeed -- String indicating the upload speed, bits per second
+ - averageSpeed -- Overall average upload speed, bits per second
+ - movingAverageSpeed -- Speed over averaged over the last several measurements, bits per second
+ - timeRemaining -- Estimated remaining upload time in seconds
+ - timeElapsed -- Number of seconds passed for this upload
+ - percentUploaded -- Percentage of the file uploaded (0 to 100)
+ - sizeUploaded -- Formatted size uploaded so far, bytes
+
+ *Adds setting 'moving_average_history_size' for defining the window size used to calculate the moving average speed.
+
+ *Adds several Formatting functions for formatting that values provided on the file object.
+ - SWFUpload.speed.formatBPS(bps) -- outputs string formatted in the best units (Gbps, Mbps, Kbps, bps)
+ - SWFUpload.speed.formatTime(seconds) -- outputs string formatted in the best units (x Hr y M z S)
+ - SWFUpload.speed.formatSize(bytes) -- outputs string formatted in the best units (w GB x MB y KB z B )
+ - SWFUpload.speed.formatPercent(percent) -- outputs string formatted with a percent sign (x.xx %)
+ - SWFUpload.speed.formatUnits(baseNumber, divisionArray, unitLabelArray, fractionalBoolean)
+ - Formats a number using the division array to determine how to apply the labels in the Label Array
+ - factionalBoolean indicates whether the number should be returned as a single fractional number with a unit (speed)
+ or as several numbers labeled with units (time)
+ */
+
+var SWFUpload;
+if (typeof(SWFUpload) === "function") {
+ SWFUpload.speed = {};
+
+ SWFUpload.prototype.initSettings = (function (oldInitSettings) {
+ return function (userSettings) {
+ if (typeof(oldInitSettings) === "function") {
+ oldInitSettings.call(this, userSettings);
+ }
+
+ this.ensureDefault = function (settingName, defaultValue) {
+ this.settings[settingName] = (userSettings[settingName] == undefined) ? defaultValue : userSettings[settingName];
+ };
+
+ // List used to keep the speed stats for the files we are tracking
+ this.fileSpeedStats = {};
+ this.speedSettings = {};
+
+ this.ensureDefault("moving_average_history_size", "10");
+
+ this.speedSettings.user_file_queued_handler = this.settings.file_queued_handler;
+ this.speedSettings.user_file_queue_error_handler = this.settings.file_queue_error_handler;
+ this.speedSettings.user_upload_start_handler = this.settings.upload_start_handler;
+ this.speedSettings.user_upload_error_handler = this.settings.upload_error_handler;
+ this.speedSettings.user_upload_progress_handler = this.settings.upload_progress_handler;
+ this.speedSettings.user_upload_success_handler = this.settings.upload_success_handler;
+ this.speedSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
+
+ this.settings.file_queued_handler = SWFUpload.speed.fileQueuedHandler;
+ this.settings.file_queue_error_handler = SWFUpload.speed.fileQueueErrorHandler;
+ this.settings.upload_start_handler = SWFUpload.speed.uploadStartHandler;
+ this.settings.upload_error_handler = SWFUpload.speed.uploadErrorHandler;
+ this.settings.upload_progress_handler = SWFUpload.speed.uploadProgressHandler;
+ this.settings.upload_success_handler = SWFUpload.speed.uploadSuccessHandler;
+ this.settings.upload_complete_handler = SWFUpload.speed.uploadCompleteHandler;
+
+ delete this.ensureDefault;
+ };
+ })(SWFUpload.prototype.initSettings);
+
+
+ SWFUpload.speed.fileQueuedHandler = function (file) {
+ if (typeof this.speedSettings.user_file_queued_handler === "function") {
+ file = SWFUpload.speed.extendFile(file);
+
+ return this.speedSettings.user_file_queued_handler.call(this, file);
+ }
+ };
+
+ SWFUpload.speed.fileQueueErrorHandler = function (file, errorCode, message) {
+ if (typeof this.speedSettings.user_file_queue_error_handler === "function") {
+ file = SWFUpload.speed.extendFile(file);
+
+ return this.speedSettings.user_file_queue_error_handler.call(this, file, errorCode, message);
+ }
+ };
+
+ SWFUpload.speed.uploadStartHandler = function (file) {
+ if (typeof this.speedSettings.user_upload_start_handler === "function") {
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
+ return this.speedSettings.user_upload_start_handler.call(this, file);
+ }
+ };
+
+ SWFUpload.speed.uploadErrorHandler = function (file, errorCode, message) {
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
+ SWFUpload.speed.removeTracking(file, this.fileSpeedStats);
+
+ if (typeof this.speedSettings.user_upload_error_handler === "function") {
+ return this.speedSettings.user_upload_error_handler.call(this, file, errorCode, message);
+ }
+ };
+ SWFUpload.speed.uploadProgressHandler = function (file, bytesComplete, bytesTotal) {
+ this.updateTracking(file, bytesComplete);
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
+
+ if (typeof this.speedSettings.user_upload_progress_handler === "function") {
+ return this.speedSettings.user_upload_progress_handler.call(this, file, bytesComplete, bytesTotal);
+ }
+ };
+
+ SWFUpload.speed.uploadSuccessHandler = function (file, serverData) {
+ if (typeof this.speedSettings.user_upload_success_handler === "function") {
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
+ return this.speedSettings.user_upload_success_handler.call(this, file, serverData);
+ }
+ };
+ SWFUpload.speed.uploadCompleteHandler = function (file) {
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
+ SWFUpload.speed.removeTracking(file, this.fileSpeedStats);
+
+ if (typeof this.speedSettings.user_upload_complete_handler === "function") {
+ return this.speedSettings.user_upload_complete_handler.call(this, file);
+ }
+ };
+
+ // Private: extends the file object with the speed plugin values
+ SWFUpload.speed.extendFile = function (file, trackingList) {
+ var tracking;
+
+ if (!file) {
+ return file;
+ }
+
+ if (trackingList) {
+ tracking = trackingList[file.id];
+ }
+
+ if (tracking) {
+ file.currentSpeed = tracking.currentSpeed;
+ file.averageSpeed = tracking.averageSpeed;
+ file.movingAverageSpeed = tracking.movingAverageSpeed;
+ file.timeRemaining = tracking.timeRemaining;
+ file.timeElapsed = tracking.timeElapsed;
+ file.percentUploaded = tracking.percentUploaded;
+ file.sizeUploaded = tracking.bytesUploaded;
+
+ } else {
+ file.currentSpeed = 0;
+ file.averageSpeed = 0;
+ file.movingAverageSpeed = 0;
+ file.timeRemaining = 0;
+ file.timeElapsed = 0;
+ file.percentUploaded = 0;
+ file.sizeUploaded = 0;
+ }
+
+ return file;
+ };
+
+ // Private: Updates the speed tracking object, or creates it if necessary
+ SWFUpload.prototype.updateTracking = function (file, bytesUploaded) {
+ var tracking = this.fileSpeedStats[file.id];
+ if (!tracking) {
+ this.fileSpeedStats[file.id] = tracking = {};
+ }
+
+ // Sanity check inputs
+ bytesUploaded = bytesUploaded || tracking.bytesUploaded || 0;
+ if (bytesUploaded < 0) {
+ bytesUploaded = 0;
+ }
+ if (bytesUploaded > file.size) {
+ bytesUploaded = file.size;
+ }
+
+ var tickTime = (new Date()).getTime();
+ if (!tracking.startTime) {
+ tracking.startTime = (new Date()).getTime();
+ tracking.lastTime = tracking.startTime;
+ tracking.currentSpeed = 0;
+ tracking.averageSpeed = 0;
+ tracking.movingAverageSpeed = 0;
+ tracking.movingAverageHistory = [];
+ tracking.timeRemaining = 0;
+ tracking.timeElapsed = 0;
+ tracking.percentUploaded = bytesUploaded / file.size;
+ tracking.bytesUploaded = bytesUploaded;
+ } else if (tracking.startTime > tickTime) {
+ this.debug("When backwards in time");
+ } else {
+ // Get time and deltas
+ var now = (new Date()).getTime();
+ var lastTime = tracking.lastTime;
+ var deltaTime = now - lastTime;
+ var deltaBytes = bytesUploaded - tracking.bytesUploaded;
+
+ if (deltaBytes === 0 || deltaTime === 0) {
+ return tracking;
+ }
+
+ // Update tracking object
+ tracking.lastTime = now;
+ tracking.bytesUploaded = bytesUploaded;
+
+ // Calculate speeds
+ tracking.currentSpeed = (deltaBytes * 8 ) / (deltaTime / 1000);
+ tracking.averageSpeed = (tracking.bytesUploaded * 8) / ((now - tracking.startTime) / 1000);
+
+ // Calculate moving average
+ tracking.movingAverageHistory.push(tracking.currentSpeed);
+ if (tracking.movingAverageHistory.length > this.settings.moving_average_history_size) {
+ tracking.movingAverageHistory.shift();
+ }
+
+ tracking.movingAverageSpeed = SWFUpload.speed.calculateMovingAverage(tracking.movingAverageHistory);
+
+ // Update times
+ tracking.timeRemaining = (file.size - tracking.bytesUploaded) * 8 / tracking.movingAverageSpeed;
+ tracking.timeElapsed = (now - tracking.startTime) / 1000;
+
+ // Update percent
+ tracking.percentUploaded = (tracking.bytesUploaded / file.size * 100);
+ }
+
+ return tracking;
+ };
+ SWFUpload.speed.removeTracking = function (file, trackingList) {
+ try {
+ trackingList[file.id] = null;
+ delete trackingList[file.id];
+ } catch (ex) {
+ }
+ };
+
+ SWFUpload.speed.formatUnits = function (baseNumber, unitDivisors, unitLabels, singleFractional) {
+ var i, unit, unitDivisor, unitLabel;
+
+ if (baseNumber === 0) {
+ return "0 " + unitLabels[unitLabels.length - 1];
+ }
+
+ if (singleFractional) {
+ unit = baseNumber;
+ unitLabel = unitLabels.length >= unitDivisors.length ? unitLabels[unitDivisors.length - 1] : "";
+ for (i = 0; i < unitDivisors.length; i++) {
+ if (baseNumber >= unitDivisors[i]) {
+ unit = (baseNumber / unitDivisors[i]).toFixed(2);
+ unitLabel = unitLabels.length >= i ? " " + unitLabels[i] : "";
+ break;
+ }
+ }
+
+ return unit + unitLabel;
+ } else {
+ var formattedStrings = [];
+ var remainder = baseNumber;
+
+ for (i = 0; i < unitDivisors.length; i++) {
+ unitDivisor = unitDivisors[i];
+ unitLabel = unitLabels.length > i ? " " + unitLabels[i] : "";
+
+ unit = remainder / unitDivisor;
+ if (i < unitDivisors.length -1) {
+ unit = Math.floor(unit);
+ } else {
+ unit = unit.toFixed(2);
+ }
+ if (unit > 0) {
+ remainder = remainder % unitDivisor;
+
+ formattedStrings.push(unit + unitLabel);
+ }
+ }
+
+ return formattedStrings.join(" ");
+ }
+ };
+
+ SWFUpload.speed.formatBPS = function (baseNumber) {
+ var bpsUnits = [1073741824, 1048576, 1024, 1], bpsUnitLabels = ["Gbps", "Mbps", "Kbps", "bps"];
+ return SWFUpload.speed.formatUnits(baseNumber, bpsUnits, bpsUnitLabels, true);
+
+ };
+ SWFUpload.speed.formatTime = function (baseNumber) {
+ var timeUnits = [86400, 3600, 60, 1], timeUnitLabels = ["d", "h", "m", "s"];
+ return SWFUpload.speed.formatUnits(baseNumber, timeUnits, timeUnitLabels, false);
+
+ };
+ SWFUpload.speed.formatBytes = function (baseNumber) {
+ var sizeUnits = [1073741824, 1048576, 1024, 1], sizeUnitLabels = ["GB", "MB", "KB", "bytes"];
+ return SWFUpload.speed.formatUnits(baseNumber, sizeUnits, sizeUnitLabels, true);
+
+ };
+ SWFUpload.speed.formatPercent = function (baseNumber) {
+ return baseNumber.toFixed(2) + " %";
+ };
+
+ SWFUpload.speed.calculateMovingAverage = function (history) {
+ var vals = [], size, sum = 0.0, mean = 0.0, varianceTemp = 0.0, variance = 0.0, standardDev = 0.0;
+ var i;
+ var mSum = 0, mCount = 0;
+
+ size = history.length;
+
+ // Check for sufficient data
+ if (size >= 8) {
+ // Clone the array and Calculate sum of the values
+ for (i = 0; i < size; i++) {
+ vals[i] = history[i];
+ sum += vals[i];
+ }
+
+ mean = sum / size;
+
+ // Calculate variance for the set
+ for (i = 0; i < size; i++) {
+ varianceTemp += Math.pow((vals[i] - mean), 2);
+ }
+
+ variance = varianceTemp / size;
+ standardDev = Math.sqrt(variance);
+
+ //Standardize the Data
+ for (i = 0; i < size; i++) {
+ vals[i] = (vals[i] - mean) / standardDev;
+ }
+
+ // Calculate the average excluding outliers
+ var deviationRange = 2.0;
+ for (i = 0; i < size; i++) {
+
+ if (vals[i] <= deviationRange && vals[i] >= -deviationRange) {
+ mCount++;
+ mSum += history[i];
+ }
+ }
+
+ } else {
+ // Calculate the average (not enough data points to remove outliers)
+ mCount = size;
+ for (i = 0; i < size; i++) {
+ mSum += history[i];
+ }
+ }
+
+ return mSum / mCount;
+ };
+
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload license.txt b/media_tree/static/media_tree/lib/swfupload/swfupload license.txt
new file mode 100644
index 0000000..80651f4
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload license.txt
@@ -0,0 +1,12 @@
+/**
+ * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
+ *
+ * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
+ *
+ * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilzén and Mammon Media and is released under the MIT License:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ */
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/AsyncJPEGEncoder.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/AsyncJPEGEncoder.as
new file mode 100644
index 0000000..4ac3108
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/AsyncJPEGEncoder.as
@@ -0,0 +1,761 @@
+ďťż// with thanks to http://www.bytearray.org/?p=775 for the optimizations
+// flash 10 only
+package
+{
+ import EncodeCompleteEvent;
+
+ import flash.display.BitmapData;
+ import flash.events.EventDispatcher;
+ import flash.utils.ByteArray;
+ import flash.utils.getTimer;
+ import flash.utils.setTimeout;
+
+ [Event(name=EncodeCompleteEvent.COMPLETE, type="EncodeCompleteEvent")]
+ [Event(name=EncodeProgressEvent.PROGRESS, type="EncodeProgressEvent")]
+
+ public class AsyncJPEGEncoder extends EventDispatcher
+ {
+ private var width:int;
+ private var height:int;
+ private var transparent:Boolean;
+
+ private var runTime:uint;
+ private var haltTime:uint;
+
+ private var loopTime:int;
+
+ private var sourceBitmapData:BitmapData;
+ private var sourceByteArray:ByteArray;
+
+ private var DCY:Number;
+ private var DCU:Number;
+ private var DCV:Number;
+
+ private var ypos:int;
+
+ // Static table initialization
+ private const ZigZag:Vector. = Vector.([
+ 0, 1, 5, 6,14,15,27,28,
+ 2, 4, 7,13,16,26,29,42,
+ 3, 8,12,17,25,30,41,43,
+ 9,11,18,24,31,40,44,53,
+ 10,19,23,32,39,45,52,54,
+ 20,22,33,38,46,51,55,60,
+ 21,34,37,47,50,56,59,61,
+ 35,36,48,49,57,58,62,63
+ ]);
+ private var YTable:Vector. = new Vector.(64, true);
+ private var UVTable:Vector. = new Vector.(64, true);
+ private var outputfDCTQuant:Vector. = new Vector.(64, true);
+ private var fdtbl_Y:Vector. = new Vector.(64, true);
+ private var fdtbl_UV:Vector. = new Vector.(64, true);
+ private var sf:int;
+
+ private const aasf:Vector. = Vector.([
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
+ 1.0, 0.785694958, 0.541196100, 0.275899379
+ ]);
+
+ private var YQT:Vector. = Vector.([
+ 16, 11, 10, 16, 24, 40, 51, 61,
+ 12, 12, 14, 19, 26, 58, 60, 55,
+ 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62,
+ 18, 22, 37, 56, 68,109,103, 77,
+ 24, 35, 55, 64, 81,104,113, 92,
+ 49, 64, 78, 87,103,121,120,101,
+ 72, 92, 95, 98,112,100,103, 99
+ ]);
+
+ private const UVQT:Vector. = Vector.([
+ 17, 18, 24, 47, 99, 99, 99, 99,
+ 18, 21, 26, 66, 99, 99, 99, 99,
+ 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99
+ ]);
+
+ private function initQuantTables(sf:int):void
+ {
+ var i:int;
+ const I64:int = 64;
+ const I8:int = 8;
+ for (i = 0; i < I64; ++i)
+ {
+ var t:int = int((YQT[i]*sf+50)*0.01);
+ if (t < 1) {
+ t = 1;
+ } else if (t > 255) {
+ t = 255;
+ }
+ YTable[ZigZag[i]] = t;
+ }
+
+ for (i = 0; i < I64; i++)
+ {
+ var u:int = int((UVQT[i]*sf+50)*0.01);
+ if (u < 1) {
+ u = 1;
+ } else if (u > 255) {
+ u = 255;
+ }
+ UVTable[ZigZag[i]] = u;
+ }
+ i = 0;
+ for (var row:int = 0; row < I8; ++row)
+ {
+ for (var col:int = 0; col < I8; ++col)
+ {
+ fdtbl_Y[i] = (1 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * I8));
+ fdtbl_UV[i] = (1 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * I8));
+ i++;
+ }
+ }
+ }
+
+ private var YDC_HT:Vector.;
+ private var UVDC_HT:Vector.;
+ private var YAC_HT:Vector.;
+ private var UVAC_HT:Vector.;
+
+ private function computeHuffmanTbl(nrcodes:Vector., std_table:Vector.):Vector.
+ {
+ var codevalue:int = 0;
+ var pos_in_table:int = 0;
+ var HT:Vector. = new Vector.(251, true);
+ var bitString:BitString;
+ for (var k:int=1; k<=16; ++k)
+ {
+ for (var j:int=1; j<=nrcodes[k]; ++j)
+ {
+ HT[std_table[pos_in_table]] = bitString = new BitString();
+ bitString.val = codevalue;
+ bitString.len = k;
+ pos_in_table++;
+ codevalue++;
+ }
+ codevalue<<=1;
+ }
+ return HT;
+ }
+
+ private var std_dc_luminance_nrcodes:Vector. = Vector.([0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0]);
+ private var std_dc_luminance_values:Vector. = Vector.([0,1,2,3,4,5,6,7,8,9,10,11]);
+ private var std_ac_luminance_nrcodes:Vector. = Vector.([0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d]);
+ private var std_ac_luminance_values:Vector. = Vector.([0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
+ 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
+ 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
+ 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
+ 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
+ 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
+ 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
+ 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
+ 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
+ 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
+ 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
+ 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
+ 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
+ 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
+ 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
+ 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
+ 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
+ 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
+ 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
+ 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa]);
+
+ private var std_dc_chrominance_nrcodes:Vector. = Vector.([0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0]);
+ private var std_dc_chrominance_values:Vector. = Vector.([0,1,2,3,4,5,6,7,8,9,10,11]);
+ private var std_ac_chrominance_nrcodes:Vector. = Vector.([0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77]);
+ private var std_ac_chrominance_values:Vector. = Vector.([0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
+ 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
+ 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
+ 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
+ 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
+ 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
+ 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
+ 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
+ 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
+ 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
+ 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
+ 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
+ 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
+ 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
+ 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
+ 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
+ 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
+ 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
+ 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
+ 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa
+ ]);
+
+ private function initHuffmanTbl():void
+ {
+ YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
+ UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
+ YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
+ UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
+ }
+
+ private var bitcode:Vector. = new Vector.(65535, true);
+ private var category:Vector. = new Vector.(65535, true);
+
+ private function initCategoryNumber():void
+ {
+ var nrlower:int = 1;
+ var nrupper:int = 2;
+ var bitString:BitString;
+ const I15:int = 15;
+ var pos:int;
+ for (var cat:int=1; cat<=I15; ++cat)
+ {
+ //Positive numbers
+ for (var nr:int=nrlower; nr= 0 )
+ {
+ if (value & uint(1 << posval) ) {
+ bytenew |= uint(1 << bytepos);
+ }
+ posval--;
+ bytepos--;
+ if (bytepos < 0)
+ {
+ if (bytenew == 0xFF)
+ {
+ byteout.writeByte(0xFF);
+ byteout.writeByte(0);
+ }
+ else {
+ byteout.writeByte(bytenew);
+ }
+ bytepos=7;
+ bytenew=0;
+ }
+ }
+ }
+
+ // DCT & quantization core
+
+ private function fDCTQuant(data:Vector., fdtbl:Vector.):Vector.
+ {
+ /* Pass 1: process rows. */
+ var dataOff:int=0;
+ var d0:Number, d1:Number, d2:Number, d3:Number, d4:Number, d5:Number, d6:Number, d7:Number;
+ var i:int;
+ const I8:int = 8;
+ const I64:int = 64;
+ for (i=0; i 0.0) ? int(fDCTQuant + 0.5) : int(fDCTQuant - 0.5);
+ }
+ return outputfDCTQuant;
+ }
+
+ // Chunk writing
+ private function writeAPP0():void
+ {
+ byteout.writeShort(0xFFE0); // marker
+ byteout.writeShort(16); // length
+ byteout.writeByte(0x4A); // J
+ byteout.writeByte(0x46); // F
+ byteout.writeByte(0x49); // I
+ byteout.writeByte(0x46); // F
+ byteout.writeByte(0); // = "JFIF",'\0'
+ byteout.writeByte(1); // versionhi
+ byteout.writeByte(1); // versionlo
+ byteout.writeByte(0); // xyunits
+ byteout.writeShort(1); // xdensity
+ byteout.writeShort(1); // ydensity
+ byteout.writeByte(0); // thumbnwidth
+ byteout.writeByte(0); // thumbnheight
+ }
+
+ private function writeSOF0():void
+ {
+ byteout.writeShort(0xFFC0); // marker
+ byteout.writeShort(17); // length, truecolor YUV JPG
+ byteout.writeByte(8); // precision
+ byteout.writeShort(height);
+ byteout.writeShort(width);
+ byteout.writeByte(3); // nrofcomponents
+ byteout.writeByte(1); // IdY
+ byteout.writeByte(0x11); // HVY
+ byteout.writeByte(0); // QTY
+ byteout.writeByte(2); // IdU
+ byteout.writeByte(0x11); // HVU
+ byteout.writeByte(1); // QTU
+ byteout.writeByte(3); // IdV
+ byteout.writeByte(0x11); // HVV
+ byteout.writeByte(1); // QTV
+ }
+
+ private function writeDQT():void
+ {
+ byteout.writeShort(0xFFDB); // marker
+ byteout.writeShort(132); // length
+ byteout.writeByte(0);
+
+ var i:int;
+ const I64:int = 64;
+ for (i=0; i = new Vector.(64, true);
+
+ private function processDU(CDU:Vector., fdtbl:Vector., DC:Number, HTDC:Vector., HTAC:Vector.):Number
+ {
+ var EOB:BitString = HTAC[0x00];
+ var M16zeroes:BitString = HTAC[0xF0];
+ var pos:int;
+ const I16:int = 16;
+ const I63:int = 63;
+ const I64:int = 64;
+ var DU_DCT:Vector. = fDCTQuant(CDU, fdtbl);
+ //ZigZag reorder
+ for (var j:int=0;j0)&&(DU[end0pos]==0); end0pos--) {};
+ //end0pos = first element in reverse order !=0
+ if ( end0pos == 0) {
+ writeBits(EOB);
+ return DC;
+ }
+ var i:int = 1;
+ var lng:int;
+ while ( i <= end0pos ) {
+ var startpos:int = i;
+ for (; (DU[i]==0) && (i<=end0pos); ++i) {}
+ var nrzeroes:int = i-startpos;
+ if ( nrzeroes >= I16 ) {
+ lng = nrzeroes>>4;
+ for (var nrmarker:int=1; nrmarker <= lng; ++nrmarker)
+ writeBits(M16zeroes);
+ nrzeroes = int(nrzeroes&0xF);
+ }
+ pos = int(32767+DU[i]);
+ writeBits(HTAC[int((nrzeroes<<4)+category[pos])]);
+ writeBits(bitcode[pos]);
+ i++;
+ }
+ if ( end0pos != I63 ) {
+ writeBits(EOB);
+ }
+ return DC;
+ }
+
+ private var YDU:Vector. = new Vector.(64, true);
+ private var UDU:Vector. = new Vector.(64, true);
+ private var VDU:Vector. = new Vector.(64, true);
+
+ private function RGB2YUV(xpos:int, ypos:int):void
+ {
+ var pos:int=0;
+ const I8:int = 8;
+ for (var y:int=0; y>16)&0xFF;
+ var G:int = (P>> 8)&0xFF;
+ var B:int = (P )&0xFF;
+ YDU[int(pos)]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-0x80;
+ UDU[int(pos)]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B));
+ VDU[int(pos)]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B));
+ ++pos;
+ }
+ }
+ }
+
+ public function AsyncJPEGEncoder(quality:int=50, run:uint=500, stop:uint=500)
+ {
+ if (quality <= 0) {
+ quality = 1;
+ }
+
+ if (quality > 100) {
+ quality = 100;
+ }
+
+ sf = quality < 50 ? int(5000 / quality) : int(200 - (quality<<1));
+
+ runTime=run;
+ haltTime=stop;
+
+ init();
+ }
+
+ private function init():void
+ {
+ ZigZag.fixed = true;
+ aasf.fixed = true;
+ YQT.fixed = true;
+ UVQT.fixed = true;
+ std_ac_chrominance_nrcodes.fixed = true;
+ std_ac_chrominance_values.fixed = true;
+ std_ac_luminance_nrcodes.fixed = true;
+ std_ac_luminance_values.fixed = true;
+ std_dc_chrominance_nrcodes.fixed = true;
+ std_dc_chrominance_values.fixed = true;
+ std_dc_luminance_nrcodes.fixed = true;
+ std_dc_luminance_values.fixed = true;
+ // Create tables
+ initHuffmanTbl();
+ initCategoryNumber();
+ initQuantTables(sf);
+ }
+
+ public function encode(bitmapData:BitmapData):void
+ {
+ internalEncode(bitmapData, bitmapData.width, bitmapData.height,
+ bitmapData.transparent);
+ }
+
+ public function encodeByteArray(byteArray:ByteArray, width:int, height:int,
+ transparent:Boolean = true):void
+ {
+ internalEncode(byteArray, width, height, transparent);
+ }
+
+ private function internalEncode(source:Object, width:int, height:int,
+ transparent:Boolean = true):void
+ {
+ this.width=width;
+ this.height=height;
+ this.transparent=transparent;
+
+ startEncode(source);
+ loopEncode();
+ }
+ private function startEncode(source:Object):void
+ {
+ // The source is either a BitmapData or a ByteArray.
+ sourceBitmapData = source as BitmapData;
+ sourceByteArray = source as ByteArray;
+
+ if (sourceByteArray) {
+ sourceByteArray.position = 0;
+ }
+
+ // Initialize bit writer
+ byteout = new ByteArray();
+
+ bytenew=0;
+ bytepos=7;
+
+ // Add JPEG headers
+ byteout.writeShort(0xFFD8); // SOI
+ writeAPP0();
+ writeDQT();
+ writeSOF0();
+ writeDHT();
+ writeSOS();
+
+ // Encode 8x8 macroblocks
+ DCY=0;
+ DCU=0;
+ DCV=0;
+
+ bytenew=0;
+ bytepos=7;
+
+ ypos=0;
+ }
+
+ private function loopEncode():void
+ {
+ //async
+ if(loopTime>runTime)
+ {
+ loopTime=0;
+ setTimeout(loopEncode, haltTime);
+ return;
+ }
+
+ if (ypos= 0 )
+ {
+ var fillbits:BitString = new BitString();
+ fillbits.len = bytepos+1;
+ fillbits.val = (1<<(bytepos+1))-1;
+ writeBits(fillbits);
+ }
+ byteout.writeShort(0xFFD9); //EOI
+
+ dispatchEvent(new EncodeCompleteEvent(byteout));
+ }
+ }
+}
+
+final class BitString
+{
+ public var len:int = 0;
+ public var val:int = 0;
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/EncodeCompleteEvent.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/EncodeCompleteEvent.as
new file mode 100644
index 0000000..bd8f614
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/EncodeCompleteEvent.as
@@ -0,0 +1,28 @@
+package
+{
+ import flash.events.Event;
+ import flash.utils.ByteArray;
+
+ public class EncodeCompleteEvent extends Event
+ {
+ public static const COMPLETE:String='encodeCompleteEvent';
+
+ private var image:ByteArray;
+
+ public function EncodeCompleteEvent(data:ByteArray, bubbles:Boolean=false, cancelable:Boolean=false)
+ {
+ super(COMPLETE, bubbles, cancelable);
+ image=data;
+ }
+
+ public function get data():ByteArray
+ {
+ return image;
+ }
+
+ override public function clone() : Event
+ {
+ return new EncodeCompleteEvent(image,bubbles,cancelable);
+ }
+ }
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ExternalCall.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ExternalCall.as
new file mode 100644
index 0000000..cac8186
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ExternalCall.as
@@ -0,0 +1,144 @@
+package {
+ import flash.external.ExternalInterface;
+
+ internal class ExternalCall
+ {
+
+ /*public function ExternalCall()
+ {
+
+ }
+ */
+
+ public static function Simple(callback:String):void {
+ ExternalInterface.call(callback);
+ }
+
+ public static function SendImage(callback:String, preview_name:String, file_id:String):void {
+ ExternalInterface.call(callback, EscapeMessage(preview_name), EscapeMessage(file_id));
+ }
+
+ public static function FileQueued(callback:String, file_object:Object):void {
+ ExternalInterface.call(callback, EscapeMessage(file_object));
+ }
+ public static function FileQueueError(callback:String, error_code:Number, file_object:Object, message:String):void {
+
+ ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(error_code), EscapeMessage(message));
+
+ }
+ public static function FileDialogComplete(callback:String, num_files_selected:Number, num_files_queued:Number, total_num_files_queued:Number):void {
+
+ ExternalInterface.call(callback, EscapeMessage(num_files_selected), EscapeMessage(num_files_queued), EscapeMessage(total_num_files_queued));
+
+ }
+
+ public static function UploadResizeStart(callback:String, file_object:Object, resizeSettings:Object):void {
+ ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(resizeSettings));
+ }
+
+ public static function UploadStart(callback:String, file_object:Object):void {
+ ExternalInterface.call(callback, EscapeMessage(file_object));
+ }
+
+ public static function UploadProgress(callback:String, file_object:Object, bytes_loaded:uint, bytes_total:uint):void {
+
+ ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(bytes_loaded), EscapeMessage(bytes_total));
+
+ }
+ public static function UploadSuccess(callback:String, file_object:Object, server_data:String, responseReceived:Boolean):void {
+
+ ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(server_data), EscapeMessage(responseReceived));
+
+ }
+ public static function UploadError(callback:String, error_code:Number, file_object:Object, message:String):void {
+
+ ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(error_code), EscapeMessage(message));
+
+ }
+ public static function UploadComplete(callback:String, file_object:Object):void {
+
+ ExternalInterface.call(callback, EscapeMessage(file_object));
+
+ }
+ public static function Debug(callback:String, message:String):void {
+
+ ExternalInterface.call(callback, EscapeMessage(message));
+ }
+
+ public static function Bool(callback:String):Boolean {
+ return ExternalInterface.call(callback);
+ }
+
+ public static function Generic(callback:String, ... rest):* {
+ var escapedRest:Array = new Array();
+ for each (var i:* in rest)
+ {
+ escapedRest.push(EscapeMessage(i));
+ }
+
+ return ExternalInterface.call(callback, escapedRest);
+ }
+
+
+ /* Escapes all the backslashes which are not translated correctly in the Flash -> JavaScript Interface
+ *
+ * These functions had to be developed because the ExternalInterface has a bug that simply places the
+ * value a string in quotes (except for a " which is escaped) in a JavaScript string literal which
+ * is executed by the browser. These often results in improperly escaped string literals if your
+ * input string has any backslash characters. For example the string:
+ * "c:\Program Files\uploadtools\"
+ * is placed in a string literal (with quotes escaped) and becomes:
+ * var __flash__temp = "\"c:\Program Files\uploadtools\\"";
+ * This statement will cause errors when executed by the JavaScript interpreter:
+ * 1) The first \" is succesfully transformed to a "
+ * 2) \P is translated to P and the \ is lost
+ * 3) \u is interpreted as a unicode character and causes an error in IE
+ * 4) \\ is translated to \
+ * 5) leaving an unescaped " which causes an error
+ *
+ * I fixed this by escaping \ characters in all outgoing strings. The above escaped string becomes:
+ * var __flash__temp = "\"c:\\Program Files\\uploadtools\\\"";
+ * which contains the correct string literal.
+ *
+ * Note: The "var __flash__temp = " portion of the example is part of the ExternalInterface not part of
+ * my escaping routine.
+ */
+ private static function EscapeMessage(message:*):* {
+ if (message is String) {
+ message = EscapeString(message);
+ }
+ else if (message is Array) {
+ message = EscapeArray(message);
+ }
+ else if (message is Object) {
+ message = EscapeObject(message);
+ }
+
+ return message;
+ }
+
+ private static function EscapeString(message:String):String {
+ var replaceSlashPattern:RegExp = /\\/g;
+ var replaceNewLinePattern:RegExp = /\n/g;
+ var replaceCarraigeReturnPattern:RegExp = /\r/g;
+ var replaceNullPattern:RegExp = /\0/g;
+
+ return message.replace(replaceSlashPattern, "\\\\").replace(replaceNewLinePattern, "\\n").replace(replaceCarraigeReturnPattern, "\\r").replace(replaceNullPattern, "\\0");
+ }
+ private static function EscapeArray(message_array:Array):Array {
+ var length:uint = message_array.length;
+ var i:uint = 0;
+ for (i; i < length; i++) {
+ message_array[i] = EscapeMessage(message_array[i]);
+ }
+ return message_array;
+ }
+ private static function EscapeObject(message_obj:Object):Object {
+ for (var name:String in message_obj) {
+ message_obj[name] = EscapeMessage(message_obj[name]);
+ }
+ return message_obj;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/FileItem.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/FileItem.as
new file mode 100644
index 0000000..105eeaa
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/FileItem.as
@@ -0,0 +1,126 @@
+package {
+ import flash.events.EventDispatcher;
+ import flash.net.FileReference;
+
+ internal class FileItem
+ {
+ private static var file_id_sequence:Number = 0; // tracks the file id sequence
+
+ private var postObject:Object;
+ public var file_reference:FileReference;
+ public var resized_uploader:MultipartURLLoader;
+ public var id:String;
+ public var index:Number = -1;
+ public var file_status:int = 0;
+ public var finalUploadProgress:Boolean = false;
+ public var upload_type:int = 0;
+ private var js_object:Object;
+
+ public static var FILE_STATUS_QUEUED:int = -1;
+ public static var FILE_STATUS_IN_PROGRESS:int = -2;
+ public static var FILE_STATUS_ERROR:int = -3;
+ public static var FILE_STATUS_SUCCESS:int = -4;
+ public static var FILE_STATUS_CANCELLED:int = -5;
+ public static var FILE_STATUS_NEW:int = -6; // This file status should never be sent to JavaScript
+
+ public static var UPLOAD_TYPE_NORMAL:int = -1;
+ public static var UPLOAD_TYPE_RESIZE:int = -2;
+
+ public function FileItem(file_reference:FileReference, control_id:String, index:Number)
+ {
+ this.postObject = {};
+ this.file_reference = file_reference;
+ this.resized_uploader = null;
+ this.id = control_id + "_" + (FileItem.file_id_sequence++);
+ this.file_status = FileItem.FILE_STATUS_NEW;
+ this.index = index;
+
+
+ this.js_object = {
+ id: this.id,
+ index: this.index,
+ uploadtype: this.upload_type,
+ post: this.GetPostObject()
+ };
+
+ // Cleanly attempt to retrieve the FileReference info
+ // this can fail and so is wrapped in try..catch
+ try {
+ this.js_object.name = this.file_reference.name;
+ this.js_object.size = this.file_reference.size;
+ this.js_object.type = this.file_reference.type || "";
+ this.js_object.creationdate = this.file_reference.creationDate || new Date(0);
+ this.js_object.modificationdate = this.file_reference.modificationDate || new Date(0);
+ } catch (ex:Error) {
+ this.file_status = FileItem.FILE_STATUS_ERROR;
+ }
+
+ this.js_object.filestatus = this.file_status;
+ }
+
+ public function GetUploader():EventDispatcher {
+ return upload_type === FileItem.UPLOAD_TYPE_NORMAL ? this.file_reference : this.resized_uploader;
+ }
+
+ public function AddParam(name:String, value:String):void {
+ this.postObject[name] = value;
+ }
+
+ public function RemoveParam(name:String):void {
+ delete this.postObject[name];
+ }
+
+ public function GetPostObject(escape:Boolean = false):Object {
+ if (escape) {
+ var escapedPostObject:Object = { };
+ for (var k:String in this.postObject) {
+ if (this.postObject.hasOwnProperty(k)) {
+ var escapedName:String = FileItem.EscapeParamName(k);
+ escapedPostObject[escapedName] = this.postObject[k];
+ }
+ }
+ return escapedPostObject;
+ } else {
+ return this.postObject;
+ }
+ }
+
+ // Create the simply file object that is passed to the browser
+ public function ToJavaScriptObject():Object {
+ this.js_object.filestatus = this.file_status;
+ this.js_object.post = this.GetPostObject(true);
+
+ return this.js_object;
+ }
+
+ public function toString():String {
+ return "FileItem - ID: " + this.id;
+ }
+
+ /*
+ // The purpose of this function is to escape the property names so when Flash
+ // passes them back to javascript they can be interpretted correctly.
+ // ***They have to be unescaped again by JavaScript.**
+ //
+ // This works around a bug where Flash sends objects this way:
+ // object.parametername = "value";
+ // instead of
+ // object["parametername"] = "value";
+ // This can be a problem if the parameter name has characters that are not
+ // allowed in JavaScript identifiers:
+ // object.parameter.name! = "value";
+ // does not work but,
+ // object["parameter.name!"] = "value";
+ // would have worked.
+ */
+ public static function EscapeParamName(name:String):String {
+ name = name.replace(/[^a-z0-9_]/gi, FileItem.EscapeCharacter);
+ name = name.replace(/^[0-9]/, FileItem.EscapeCharacter);
+ return name;
+ }
+ public static function EscapeCharacter():String {
+ return "$" + ("0000" + arguments[0].charCodeAt(0).toString(16)).substr(-4, 4);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizer.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizer.as
new file mode 100644
index 0000000..956de82
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizer.as
@@ -0,0 +1,203 @@
+ďťż/*
+ * http://code.google.com/p/sync-to-async/ -- Apache 2.0 License
+ */
+
+// FIXME -- handler errors for the loader and file_reference objects
+
+package
+{
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
+ import flash.display.Loader;
+ import flash.errors.IOError;
+ import flash.events.ErrorEvent;
+ import flash.events.Event;
+ import flash.events.IOErrorEvent;
+ import flash.events.EventDispatcher;
+ import flash.filters.BitmapFilter;
+ import flash.filters.BitmapFilterQuality;
+ import flash.filters.BlurFilter;
+ import flash.geom.Matrix;
+ import flash.geom.Point;
+ import flash.geom.Rectangle;
+ import flash.net.FileReference;
+ import flash.utils.ByteArray;
+ import cmodule.jpegencoder.CLibInit;
+
+ /*
+ Technique adapted from Kun Janos (http://kun-janos.ro/blog/?p=107)
+ */
+ public class ImageResizer extends EventDispatcher
+ {
+ private var file:FileItem = null;
+ private var targetWidth:Number = 0;
+ private var targetHeight:Number = 0;
+ private var newWidth:Number = 1;
+ private var newHeight:Number = 1;
+ private var encoder:Number = ImageResizer.JPEGENCODER;
+ private var quality:Number = 100;
+ private var allowEnlarging:Boolean = true;
+
+ public static const JPEGENCODER:Number = -1;
+ public static const PNGENCODE:Number = -2;
+
+ public function ImageResizer(file:FileItem, targetWidth:Number, targetHeight:Number, encoder:Number, quality:Number = 100, allowEnlarging:Boolean = true) {
+ this.file = file;
+ this.targetHeight = targetHeight;
+ this.targetWidth = targetWidth;
+ this.encoder = encoder;
+ this.quality = quality;
+ this.allowEnlarging = allowEnlarging;
+
+ if (this.encoder != ImageResizer.JPEGENCODER && this.encoder != ImageResizer.PNGENCODE) {
+ this.encoder = ImageResizer.JPEGENCODER;
+ }
+ if (this.quality < 0 || this.quality > 100) {
+ this.quality = 100;
+ }
+ }
+
+ public function ResizeImage():void {
+ try {
+ this.file.file_reference.addEventListener(Event.COMPLETE, this.fileLoad_Complete);
+ this.file.file_reference.load();
+ } catch (ex:Error) {
+ this.file.file_reference.removeEventListener(Event.COMPLETE, this.fileLoad_Complete);
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, "Loading from file reference: " + ex.message));
+ this.file = null;
+ }
+ }
+
+ private function fileLoad_Complete(event:Event):void {
+ try {
+ event.target.removeEventListener(Event.COMPLETE, this.fileLoad_Complete);
+
+ var loader:Loader = new Loader();
+
+ // Load the image data, resizing takes place in the event handler
+ loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.loader_Complete);
+ loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.loader_Error);
+
+ loader.loadBytes(FileReference(event.target).data);
+ } catch (ex:Error) {
+ loader.removeEventListener(Event.COMPLETE, this.loader_Complete);
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, "Loading Loader" + ex.message));
+ this.file = null;
+ }
+ }
+ private function loader_Error(event:IOErrorEvent):void {
+ try {
+ event.target.removeEventListener(Event.COMPLETE, this.loader_Complete);
+ event.target.removeEventListener(IOErrorEvent.IO_ERROR, this.loader_Error);
+ } catch (ex:Error) {}
+
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, "Resizing: " + event.text));
+ }
+
+ private function loader_Complete(event:Event):void {
+ try {
+ var bytes:ByteArray;
+
+ event.target.removeEventListener(Event.COMPLETE, this.loader_Complete);
+ event.target.removeEventListener(IOErrorEvent.IO_ERROR, this.loader_Error);
+
+ var loader:Loader = Loader(event.target.loader);
+
+ var contentType:String = loader.contentLoaderInfo.contentType;
+
+ // Calculate the new image size
+ var targetRatio:Number = this.targetWidth / this.targetHeight;
+ var imgRatio:Number = loader.width / loader.height;
+ this.newHeight = (targetRatio > imgRatio) ? this.targetHeight : Math.min(this.targetWidth / imgRatio, this.targetHeight);
+ this.newWidth = (targetRatio > imgRatio) ? Math.min(imgRatio * this.targetHeight, this.targetWidth) : this.targetWidth;
+
+ var resizedBmp:BitmapData = null;
+
+ // Get the image data
+ var bmp:BitmapData = Bitmap(loader.content).bitmapData;
+
+ loader.unload();
+ loader = null;
+
+ // If enlarging is not allowed but the new width causes enlarging then adjust the dimensions
+ if (!this.allowEnlarging && (this.newWidth > bmp.width || this.newHeight > bmp.height)) {
+ this.newWidth = bmp.width;
+ this.newHeight = bmp.height;
+ }
+
+ // Blur it a bit if it is sizing smaller
+ if (this.newWidth < bmp.width || this.newHeight < bmp.height) {
+ // Apply the blur filter that helps clean up the resized image result
+ var blurMultiplier:Number = 1.15; // 1.25;
+ var blurXValue:Number = Math.max(1, bmp.width / this.newWidth) * blurMultiplier;
+ var blurYValue:Number = Math.max(1, bmp.height / this.newHeight) * blurMultiplier;
+
+ var blurFilter:BlurFilter = new BlurFilter(blurXValue, blurYValue, int(BitmapFilterQuality.LOW));
+ bmp.applyFilter(bmp, new Rectangle(0, 0, bmp.width, bmp.height), new Point(0, 0), blurFilter);
+ }
+
+ if (this.newWidth < bmp.width || this.newHeight < bmp.height || this.IsTranscoding(contentType)) {
+ // Apply the resizing
+ var matrix:Matrix = new Matrix();
+ matrix.identity();
+ matrix.createBox(this.newWidth / bmp.width, this.newHeight / bmp.height);
+
+ resizedBmp = new BitmapData(this.newWidth, this.newHeight, true, 0x000000);
+ resizedBmp.draw(bmp, matrix, null, null, null, true);
+
+ bmp.dispose();
+
+ if (this.encoder == ImageResizer.PNGENCODE) {
+ var pngEncoder:PNGEncoder = new PNGEncoder(PNGEncoder.TYPE_SUBFILTER, 1);
+ pngEncoder.addEventListener(EncodeCompleteEvent.COMPLETE, this.EncodeCompleteHandler);
+ pngEncoder.addEventListener(ErrorEvent.ERROR, this.EncodeErrorHandler);
+ pngEncoder.encode(resizedBmp);
+ } else {
+ //var jpegEncoder:AsyncJPEGEncoder = new AsyncJPEGEncoder(this.quality, 0, 100);
+
+ //jpegEncoder.addEventListener(EncodeCompleteEvent.COMPLETE, this.EncodeCompleteHandler);
+ //jpegEncoder.encode(resizedBmp);
+
+ this.ba = resizedBmp.getPixels(resizedBmp.rect);
+ this.ba.position = 0;
+ this.baOut = new ByteArray();
+
+ var cLibEncoder:Object = (new CLibInit).init();
+ cLibEncoder.encodeAsync(compressFinished, this.ba, this.baOut, resizedBmp.width, resizedBmp.height, this.quality);
+ }
+ } else {
+ // Just send along the unmodified data
+ dispatchEvent(new ImageResizerEvent(ImageResizerEvent.COMPLETE, this.file.file_reference.data, this.encoder));
+ }
+
+ } catch (ex:Error) {
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, "Resizing: " + ex.message));
+ }
+
+ this.file = null;
+ }
+
+ private function IsTranscoding(type:String):Boolean {
+ return !((type == "image/jpeg" && this.encoder == ImageResizer.JPEGENCODER) || (type == "image/png" && this.encoder == ImageResizer.PNGENCODE));
+ }
+
+ private function EncodeErrorHandler(e:ErrorEvent):void {
+ dispatchEvent(e);
+ }
+
+ private var ba:ByteArray;
+ private var baOut:ByteArray;
+ private function compressFinished(out:ByteArray):void {
+ this.baOut.position = 0;
+ this.ba.length = 0;
+
+ this.EncodeCompleteHandler(new EncodeCompleteEvent(baOut));
+ }
+
+ private function EncodeCompleteHandler(e:EncodeCompleteEvent):void {
+ dispatchEvent(new ImageResizerEvent(ImageResizerEvent.COMPLETE, e.data, this.encoder));
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizerEvent.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizerEvent.as
new file mode 100644
index 0000000..e1860cf
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/ImageResizerEvent.as
@@ -0,0 +1,20 @@
+ďťżpackage
+{
+ import flash.events.Event;
+ import flash.utils.ByteArray;
+
+ public class ImageResizerEvent extends Event
+ {
+ public var data:ByteArray;
+ public var encoding:Number;
+
+ public static const COMPLETE:String = "COMPLETE";
+
+ public function ImageResizerEvent (type:String, data:ByteArray, encoding:Number)
+ {
+ super(type);
+ this.data = data;
+ this.encoding = encoding;
+ }
+ }
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/MultipartURLLoader.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/MultipartURLLoader.as
new file mode 100644
index 0000000..1dcb296
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/MultipartURLLoader.as
@@ -0,0 +1,352 @@
+ďťżpackage
+{
+ import flash.errors.IllegalOperationError;
+ import flash.errors.IOError;
+ import flash.events.DataEvent;
+ import flash.events.ErrorEvent;
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.HTTPStatusEvent;
+ import flash.events.IOErrorEvent;
+ import flash.events.ProgressEvent;
+ import flash.events.SecurityErrorEvent;
+ import flash.net.URLLoader;
+ import flash.net.URLLoaderDataFormat;
+ import flash.net.URLRequest;
+ import flash.net.URLRequestHeader;
+ import flash.net.URLRequestMethod;
+ import flash.net.URLVariables;
+ import flash.utils.ByteArray;
+ import flash.utils.Dictionary;
+ import flash.utils.Endian;
+ import flash.utils.setTimeout;
+ import flash.utils.clearInterval;
+
+ /**
+ * Multipart URL Loader
+ *
+ * Original idea by Marston Development Studio - http://marstonstudio.com/?p=36
+ *
+ * License: MIT
+ *
+ * @author Eugene Zatepyakin
+ * @version 1.3
+ * @link http://blog.inspirit.ru/
+ *
+ *
+ * Heavily modified from the original version. Removed multiple file support.
+ * Removed optional async data preparation (always async)
+ * After data is preparted the upload immediately starts.
+ * Updated to look and behave similar to the FileReference upload API
+ */
+ public class MultipartURLLoader extends EventDispatcher
+ {
+ public static var BLOCK_SIZE:uint = 64 * 1024;
+
+ private var _loader:URLLoader;
+ private var _request:URLRequest;
+ private var _boundary:String;
+
+ private var _fileName:String;
+ private var _uploadDataFieldName:String;
+ private var _fileData:ByteArray;
+ private var _data:ByteArray;
+ private var _httpStatus:Number;
+
+ private var asyncWriteTimeoutId:Number;
+
+
+ public function MultipartURLLoader(fileData:ByteArray, fileName:String) {
+ _loader = new URLLoader();
+ _fileData = fileData;
+ _fileName = fileName;
+ }
+
+ public function upload(request:URLRequest, uploadDataFieldName:String = "Filedata"):void {
+ dispatchEvent(new Event(Event.OPEN, false, false));
+
+ this._httpStatus = undefined;
+ this._request = request;
+ this._uploadDataFieldName = uploadDataFieldName;
+ this.constructPostDataAsync();
+ }
+
+ /**
+ * Stop loader action
+ */
+ public function cancel():void
+ {
+ try {
+ clearInterval(this.asyncWriteTimeoutId);
+ _loader.close();
+ } catch ( e:Error ) { }
+
+ this.destroy();
+ }
+
+
+
+ /**
+ * Dispose all class instance objects
+ */
+ public function dispose(): void
+ {
+ try {
+ this.cancel();
+ } catch (ex:Error) {}
+ }
+
+ /**
+ * Generate random boundary
+ * @return Random boundary
+ */
+ public function getBoundary():String
+ {
+ if (_boundary == null) {
+ _boundary = '';
+ for (var i:int = 0; i < 0x20; i++ ) {
+ _boundary += String.fromCharCode( int( 97 + Math.random() * 25 ) );
+ }
+ }
+ return _boundary;
+ }
+
+ private function doSend():void
+ {
+ var urlRequest:URLRequest = new URLRequest();
+ urlRequest.url = this._request.url;
+ //urlRequest.contentType = 'multipart/form-data; boundary=' + getBoundary();
+ urlRequest.method = URLRequestMethod.POST;
+ urlRequest.data = _data;
+
+ urlRequest.requestHeaders = this._request.requestHeaders.concat();
+ urlRequest.requestHeaders.push(new URLRequestHeader('Content-Type', 'multipart/form-data; boundary=' + getBoundary()));
+
+ this.addListener();
+ try {
+ _loader.load(urlRequest);
+ } catch (ex:Error) {
+ dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, "Exception: " + ex.message));
+ this.destroy();
+ }
+
+ }
+
+ private function constructPostDataAsync():void
+ {
+ clearInterval(this.asyncWriteTimeoutId);
+
+ this._data = new ByteArray();
+ this._data.endian = Endian.BIG_ENDIAN;
+
+ this._data = constructVariablesPart(this._data);
+ this._data = getFilePartHeader(this._data, this._fileName);
+
+ this.asyncWriteTimeoutId = setTimeout(this.writeChunkLoop, 10, this._data, this._fileData, 0);
+
+ }
+
+ private function writeChunkLoop(dest:ByteArray, data:ByteArray, p:uint = 0):void
+ {
+ try {
+ var len:uint = Math.min(BLOCK_SIZE, data.length - p);
+ dest.writeBytes(data, p, len);
+
+ if (len < BLOCK_SIZE || p + len >= data.length) {
+ // Finished writing file bytearray
+ dest = LINEBREAK(dest);
+ this._data = closeFilePartsData(_data);
+ this._data = closeDataObject(_data);
+ this.doSend();
+ return;
+ }
+
+ this.asyncWriteTimeoutId = setTimeout(this.writeChunkLoop, 10, dest, data, p + len);
+ } catch (ex:Error) {
+ dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR));
+ this.destroy();
+ }
+ }
+
+ private function closeDataObject(postData:ByteArray):ByteArray
+ {
+ postData = BOUNDARY(postData);
+ postData = DOUBLEDASH(postData);
+ return postData;
+ }
+
+ private function constructVariablesPart(postData:ByteArray):ByteArray
+ {
+ var i:uint;
+ var bytes:String;
+
+ if (this._request.data is URLVariables) {
+ for (var name:String in this._request.data)
+ {
+ postData = BOUNDARY(postData);
+ postData = LINEBREAK(postData);
+ bytes = 'Content-Disposition: form-data; name="' + name + '"';
+ for ( i = 0; i < bytes.length; i++ ) {
+ postData.writeByte( bytes.charCodeAt(i) );
+ }
+ postData = LINEBREAK(postData);
+ postData = LINEBREAK(postData);
+ postData.writeUTFBytes(this._request.data[name]);
+ postData = LINEBREAK(postData);
+ }
+ }
+
+ return postData;
+ }
+
+ private function closeFilePartsData(postData:ByteArray):ByteArray
+ {
+ //var i:uint;
+ //var bytes:String;
+ //
+ //postData = LINEBREAK(postData);
+ //postData = BOUNDARY(postData);
+ //postData = LINEBREAK(postData);
+ //bytes = 'Content-Disposition: form-data; name="Upload"';
+ //for ( i = 0; i < bytes.length; i++ ) {
+ //postData.writeByte( bytes.charCodeAt(i) );
+ //}
+ //postData = LINEBREAK(postData);
+ //postData = LINEBREAK(postData);
+ //bytes = 'Submit Query';
+ //for ( i = 0; i < bytes.length; i++ ) {
+ //postData.writeByte( bytes.charCodeAt(i) );
+ //}
+ //postData = LINEBREAK(postData);
+
+ return postData;
+ }
+
+ private function getFilePartHeader(postData:ByteArray, fileName:String):ByteArray
+ {
+ var i:uint;
+ var bytes:String;
+
+ postData = BOUNDARY(postData);
+ postData = LINEBREAK(postData);
+ bytes = 'Content-Disposition: form-data; name="' + this._uploadDataFieldName + '"; filename="';
+ for ( i = 0; i < bytes.length; i++ ) {
+ postData.writeByte( bytes.charCodeAt(i) );
+ }
+
+ postData.writeUTFBytes(fileName);
+ postData = QUOTATIONMARK(postData);
+
+ postData = LINEBREAK(postData);
+ bytes = 'Content-Type: application/octet-stream';
+ for ( i = 0; i < bytes.length; i++ ) {
+ postData.writeByte( bytes.charCodeAt(i) );
+ }
+ postData = LINEBREAK(postData);
+ postData = LINEBREAK(postData);
+
+ return postData;
+ }
+
+ private function onComplete( event: Event ): void
+ {
+ if (this._httpStatus === 200) {
+ dispatchEvent(event);
+ if (this._loader && this._loader.data.length > 0) {
+ dispatchEvent(new DataEvent(DataEvent.UPLOAD_COMPLETE_DATA, event.bubbles, event.cancelable, this._loader.data));
+ }
+ } else {
+ dispatchEvent(new HTTPStatusEvent(HTTPStatusEvent.HTTP_STATUS, event.bubbles, event.cancelable, this._httpStatus));
+ }
+ this.destroy();
+ }
+
+ private function onIOError( event: IOErrorEvent ): void
+ {
+ dispatchEvent( event );
+ this.destroy();
+ }
+
+ private function onSecurityError( event: SecurityErrorEvent ): void
+ {
+ dispatchEvent( event );
+ this.destroy();
+ }
+
+ private function onHTTPStatus( event: HTTPStatusEvent ): void
+ {
+ this._httpStatus = event.status;
+ }
+
+ private function addListener(): void
+ {
+ if (this._loader != null) {
+ this._loader.addEventListener( Event.COMPLETE, this.onComplete, false, 0, false );
+ this._loader.addEventListener( IOErrorEvent.IO_ERROR, this.onIOError, false, 0, false );
+ this._loader.addEventListener( HTTPStatusEvent.HTTP_STATUS, this.onHTTPStatus, false, 0, false );
+ this._loader.addEventListener( SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError, false, 0, false );
+ }
+ }
+
+ private function removeListener(): void
+ {
+ if (this._loader != null) {
+ this._loader.removeEventListener( Event.COMPLETE, this.onComplete );
+ this._loader.removeEventListener( IOErrorEvent.IO_ERROR, this.onIOError );
+ this._loader.removeEventListener( HTTPStatusEvent.HTTP_STATUS, this.onHTTPStatus );
+ this._loader.removeEventListener( SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError );
+ }
+ }
+
+ private function BOUNDARY(p:ByteArray):ByteArray
+ {
+ var l:int = getBoundary().length;
+ p = DOUBLEDASH(p);
+ for (var i:int = 0; i < l; i++ ) {
+ p.writeByte( _boundary.charCodeAt( i ) );
+ }
+ return p;
+ }
+
+ private function LINEBREAK(p:ByteArray):ByteArray
+ {
+ p.writeShort(0x0d0a);
+ return p;
+ }
+
+ private function QUOTATIONMARK(p:ByteArray):ByteArray
+ {
+ p.writeByte(0x22);
+ return p;
+ }
+
+ private function DOUBLEDASH(p:ByteArray):ByteArray
+ {
+ p.writeShort(0x2d2d);
+ return p;
+ }
+
+ private function destroy():void {
+ try {
+ this.removeListener();
+ } catch (ex:Error) {}
+
+ this._loader = null;
+ this._request = null;
+ this._boundary = null;
+
+ this._fileName = null;
+ this._uploadDataFieldName = null;
+ this._fileData = null;
+ this._data = null;
+ this._httpStatus = undefined;
+
+ try {
+ clearInterval(this.asyncWriteTimeoutId);
+ } catch (ex:Error) { }
+
+ this.asyncWriteTimeoutId = undefined;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/PNGEncoder.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/PNGEncoder.as
new file mode 100644
index 0000000..26edeaa
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/PNGEncoder.as
@@ -0,0 +1,295 @@
+ďťż/*
+ * http://code.google.com/p/as3corelib/ -- New BSD License
+ * Modified to work asynchronously
+ * */
+
+package
+{
+ import flash.utils.ByteArray;
+ import flash.display.BitmapData;
+ import flash.geom.Rectangle;
+ import flash.events.EventDispatcher;
+ import flash.events.ErrorEvent;
+ import flash.utils.setTimeout;
+
+ public class PNGEncoder extends EventDispatcher {
+ public static const TYPE_NORMAL:uint = 0;
+ public static const TYPE_SUBFILTER:uint = 1;
+
+ private var img:BitmapData;
+ private var png:ByteArray;
+ private var IDAT:ByteArray;
+
+ private var type:uint;
+ private var delay:int;
+
+ public function PNGEncoder(type:uint = PNGEncoder.TYPE_NORMAL, delay:int = 0) {
+ super();
+
+ this.type = type;
+ this.delay = delay;
+
+ PNGEncoder.computeCRCTable();
+
+ }
+
+ public function encode(img:BitmapData):void {
+ try {
+ // Create output byte array
+ this.png = new ByteArray();
+ this.img = img;
+
+ // Write PNG signature
+ this.png.writeUnsignedInt(0x89504e47);
+ this.png.writeUnsignedInt(0x0D0A1A0A);
+
+ // Build IHDR chunk
+ var IHDR:ByteArray = new ByteArray();
+ IHDR.writeInt(this.img.width);
+ IHDR.writeInt(this.img.height);
+ if(img.transparent || this.type == PNGEncoder.TYPE_NORMAL)
+ {
+ IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA
+ }
+ else
+ {
+ IHDR.writeUnsignedInt(0x08020000); //24bit RGB
+ }
+
+ IHDR.writeByte(0);
+
+ PNGEncoder.writeChunk(this.png, 0x49484452, IHDR);
+
+ // Build IDAT chunk
+ this.IDAT = new ByteArray();
+
+ // Start encoding loop
+ encodeLoop();
+ } catch (ex:Error) {
+ this.CleanUp();
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, ex.message));
+ }
+ }
+
+ private function encodeLoop():void {
+ try {
+ switch(this.type)
+ {
+ case PNGEncoder.TYPE_NORMAL:
+ setTimeout(this.writeRaw, this.delay);
+ break;
+ case PNGEncoder.TYPE_SUBFILTER:
+ setTimeout(this.writeSub, this.delay);
+ break;
+ default:
+ this.CleanUp();
+ break;
+ }
+ } catch (ex:Error) {
+ this.CleanUp();
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, ex.message));
+ }
+
+ }
+
+ private function encodeEnd():void {
+ try {
+ this.IDAT.compress();
+ PNGEncoder.writeChunk(this.png, 0x49444154, this.IDAT);
+
+ // Build IEND chunk
+ PNGEncoder.writeChunk(this.png, 0x49454E44, null);
+
+ // trigger complete event
+ dispatchEvent(new EncodeCompleteEvent(this.png));
+ } catch (ex:Error) {
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, ex.message));
+ } finally {
+ this.CleanUp();
+ }
+ }
+
+ private var encodingRow:int = 0;
+ private function writeRaw():void
+ {
+ try {
+ if (this.encodingRow < this.img.height) {
+ if (!this.img.transparent) {
+ // Get the whole row
+ var subImage:ByteArray = this.img.getPixels(new Rectangle(0, encodingRow, this.img.width, 1));
+ //Here we overwrite the alpha value of the first pixel
+ //to be the filter 0 flag
+ subImage[0] = 0;
+ this.IDAT.writeBytes(subImage);
+ //And we add a byte at the end to wrap the alpha values
+ this.IDAT.writeByte(0xff);
+ } else {
+ // Read and write a whole image row
+ this.IDAT.writeByte(0);
+ var p:uint;
+ for (var j:int = 0; j < this.img.width; j++) {
+ p = this.img.getPixel32(j, this.encodingRow);
+ this.IDAT.writeUnsignedInt(uint(((p & 0xFFFFFF) << 8) | (p >>> 24)));
+ }
+ }
+
+ this.encodingRow++;
+ setTimeout(this.writeRaw, this.delay);
+ } else {
+ this.encodeEnd();
+ }
+ } catch (ex:Error) {
+ this.CleanUp();
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, ex.message));
+ }
+ }
+
+ private function writeSub():void
+ {
+ try {
+ var r1:uint = 0;
+ var g1:uint = 0;
+ var b1:uint = 0;
+ var a1:uint = 0;
+
+ var r2:uint;
+ var g2:uint;
+ var b2:uint;
+ var a2:uint;
+
+ var r3:uint;
+ var g3:uint;
+ var b3:uint;
+ var a3:uint;
+
+ var p:uint;
+ var h:int = this.img.height;
+ var w:int = this.img.width;
+
+ var j:int = 0;
+
+ if (this.encodingRow < h) {
+ // no filter
+ this.IDAT.writeByte(1);
+ if (!this.img.transparent) {
+ a1 = 0xff;
+ for(j = 0; j < w; j++) {
+ p = img.getPixel(j, this.encodingRow);
+
+ r2 = p >> 16 & 0xff;
+ g2 = p >> 8 & 0xff;
+ b2 = p & 0xff;
+
+ r3 = (r2 - r1 + 256) & 0xff;
+ g3 = (g2 - g1 + 256) & 0xff;
+ b3 = (b2 - b1 + 256) & 0xff;
+
+ this.IDAT.writeByte(r3);
+ this.IDAT.writeByte(g3);
+ this.IDAT.writeByte(b3);
+
+ r1 = r2;
+ g1 = g2;
+ b1 = b2;
+ a1 = 0;
+ }
+ } else {
+ for(j = 0; j < w; j++) {
+ p = img.getPixel32(j, this.encodingRow);
+
+ a2 = p >> 24 & 0xff;
+ r2 = p >> 16 & 0xff;
+ g2 = p >> 8 & 0xff;
+ b2 = p & 0xff;
+
+ r3 = (r2 - r1 + 256) & 0xff;
+ g3 = (g2 - g1 + 256) & 0xff;
+ b3 = (b2 - b1 + 256) & 0xff;
+ a3 = (a2 - a1 + 256) & 0xff;
+
+ this.IDAT.writeByte(r3);
+ this.IDAT.writeByte(g3);
+ this.IDAT.writeByte(b3);
+ this.IDAT.writeByte(a3);
+
+ r1 = r2;
+ g1 = g2;
+ b1 = b2;
+ a1 = a2;
+ }
+ }
+
+ this.encodingRow++;
+ setTimeout(this.writeSub, this.delay);
+ } else {
+ this.encodeEnd();
+ }
+ } catch (ex:Error) {
+ this.CleanUp();
+ dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, ex.message));
+ }
+ }
+
+ private function CleanUp():void {
+ this.png = null;
+ this.img = null;
+ this.IDAT = null;
+ this.encodingRow = 0;
+ }
+
+ private static var crcTable:Array;
+ private static var crcTableComputed:Boolean = false;
+
+ private static function computeCRCTable():void {
+ if (!crcTableComputed) {
+ PNGEncoder.crcTableComputed = true;
+ PNGEncoder.crcTable = [];
+ for (var n:uint = 0; n < 256; n++) {
+ var c:uint = n;
+ for (var k:uint = 0; k < 8; k++) {
+ if (c & 1) {
+ c = uint(uint(0xedb88320) ^
+ uint(c >>> 1));
+ } else {
+ c = uint(c >>> 1);
+ }
+ }
+ PNGEncoder.crcTable[n] = c;
+ }
+ }
+ }
+
+ private static function writeChunk(png:ByteArray, type:uint, data:ByteArray):void {
+ var len:uint = 0;
+ if (data != null) {
+ len = data.length;
+ }
+
+ png.writeUnsignedInt(len);
+
+ var p:uint = png.position;
+
+ png.writeUnsignedInt(type);
+
+ if (data != null) {
+ png.writeBytes(data);
+ }
+
+ var e:uint = png.position;
+ png.position = p;
+
+ var c:uint = 0xffffffff;
+ for (var i:int = 0; i < (e - p); i++) {
+ c = uint(PNGEncoder.crcTable[
+ (c ^ png.readUnsignedByte()) &
+ 0xff] ^ (c >>> 8));
+ }
+
+ c = uint(c ^ uint(0xffffffff));
+
+ png.position = e;
+
+ png.writeUnsignedInt(c);
+ }
+ }
+}
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload FP10.as3proj b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload FP10.as3proj
new file mode 100644
index 0000000..1b68138
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload FP10.as3proj
@@ -0,0 +1,81 @@
+ďťż
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ deploy.bat
+
+
+
+
+
+
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload.as b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload.as
new file mode 100644
index 0000000..bc33755
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/SWFUpload.as
@@ -0,0 +1,1679 @@
+/* Todo:
+* Missing initial progress event
+* Improve resizing/encoding so it doesn't lock up browser.
+* */
+
+package {
+ import flash.display.BlendMode;
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Loader;
+ import flash.display.Stage;
+ import flash.display.Sprite;
+ import flash.display.StageAlign;
+ import flash.display.StageScaleMode;
+ import flash.net.FileReferenceList;
+ import flash.net.FileReference;
+ import flash.net.FileFilter;
+ import flash.net.URLRequest;
+ import flash.net.URLRequestMethod;
+ import flash.net.URLVariables;
+ import flash.events.*;
+ import flash.external.ExternalInterface;
+ import flash.system.Security;
+ import flash.text.AntiAliasType;
+ import flash.text.GridFitType;
+ import flash.text.StaticText;
+ import flash.text.StyleSheet;
+ import flash.text.TextDisplayMode;
+ import flash.text.TextField;
+ import flash.text.TextFieldType;
+ import flash.text.TextFieldAutoSize;
+ import flash.text.TextFormat;
+ import flash.ui.Mouse;
+ import flash.utils.ByteArray;
+ import flash.utils.Timer;
+
+ import FileItem;
+ import ExternalCall;
+ import ImageResizer;
+ import ImageResizerEvent;
+ import MultipartURLLoader;
+
+ public class SWFUpload extends Sprite {
+ // Cause SWFUpload to start as soon as the movie starts
+ public static function main():void
+ {
+ var SWFUpload:SWFUpload = new SWFUpload();
+ }
+
+
+ private const build_number:String = "2.5.0 2010-02-17 Beta 3";
+
+ // State tracking variables
+ private var fileBrowserMany:FileReferenceList = new FileReferenceList();
+ private var fileBrowserOne:FileReference = null; // This isn't set because it can't be reused like the FileReferenceList. It gets setup in the SelectFile method
+
+ private var file_queue:Array = new Array(); // holds a list of all items that are to be uploaded.
+ private var current_file_item:FileItem = null; // the item that is currently being uploaded.
+
+ private var file_index:Array = new Array();
+
+ private var successful_uploads:Number = 0; // Tracks the uploads that have been completed
+ private var queue_errors:Number = 0; // Tracks files rejected during queueing
+ private var upload_errors:Number = 0; // Tracks files that fail upload
+ private var upload_cancelled:Number = 0; // Tracks number of cancelled files
+ private var queued_uploads:Number = 0; // Tracks the FileItems that are waiting to be uploaded.
+
+ private var valid_file_extensions:Array = new Array();// Holds the parsed valid extensions.
+
+ private var serverDataTimer:Timer = null;
+ private var assumeSuccessTimer:Timer = null;
+
+ private var sizeTimer:Timer;
+ private var hasCalledFlashReady:Boolean = false;
+
+ // Callbacks
+ private var flashReady_Callback:String;
+ private var fileDialogStart_Callback:String;
+ private var fileQueued_Callback:String;
+ private var fileQueueError_Callback:String;
+ private var fileDialogComplete_Callback:String;
+
+ private var uploadResizeStart_Callback:String;
+ private var uploadStart_Callback:String;
+ private var uploadProgress_Callback:String;
+ private var uploadError_Callback:String;
+ private var uploadSuccess_Callback:String;
+
+ private var uploadComplete_Callback:String;
+
+ private var debug_Callback:String;
+
+ private var mouseOut_Callback:String;
+ private var mouseOver_Callback:String;
+ private var mouseClick_Callback:String;
+
+ // Values passed in from the HTML
+ private var movieName:String;
+ private var uploadURL:String;
+ private var filePostName:String;
+ private var uploadPostObject:Object;
+ private var fileTypes:String;
+ private var fileTypesDescription:String;
+ private var fileSizeLimit:Number;
+ private var fileUploadLimit:Number = 0;
+ private var fileQueueLimit:Number = 0;
+ private var useQueryString:Boolean = false;
+ private var requeueOnError:Boolean = false;
+ private var httpSuccess:Array = [];
+ private var assumeSuccessTimeout:Number = 0;
+ private var debugEnabled:Boolean;
+
+ private var buttonLoader:Loader;
+ private var buttonTextField:TextField;
+ private var buttonCursorSprite:Sprite;
+ private var buttonImageURL:String;
+ //private var buttonWidth:Number;
+ //private var buttonHeight:Number;
+ private var buttonText:String;
+ private var buttonTextStyle:String;
+ private var buttonTextTopPadding:Number;
+ private var buttonTextLeftPadding:Number;
+ private var buttonAction:Number;
+ private var buttonCursor:Number;
+ private var buttonStateOver:Boolean;
+ private var buttonStateMouseDown:Boolean;
+ private var buttonStateDisabled:Boolean;
+
+ // Error code "constants"
+ // Size check constants
+ private var SIZE_TOO_BIG:Number = 1;
+ private var SIZE_ZERO_BYTE:Number = -1;
+ private var SIZE_OK:Number = 0;
+
+ // Queue errors
+ private var ERROR_CODE_QUEUE_LIMIT_EXCEEDED:Number = -100;
+ private var ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:Number = -110;
+ private var ERROR_CODE_ZERO_BYTE_FILE:Number = -120;
+ private var ERROR_CODE_INVALID_FILETYPE:Number = -130;
+
+ // Upload Errors
+ private var ERROR_CODE_HTTP_ERROR:Number = -200;
+ private var ERROR_CODE_MISSING_UPLOAD_URL:Number = -210;
+ private var ERROR_CODE_IO_ERROR:Number = -220;
+ private var ERROR_CODE_SECURITY_ERROR:Number = -230;
+ private var ERROR_CODE_UPLOAD_LIMIT_EXCEEDED:Number = -240;
+ private var ERROR_CODE_UPLOAD_FAILED:Number = -250;
+ private var ERROR_CODE_SPECIFIED_FILE_ID_NOT_FOUND:Number = -260;
+ private var ERROR_CODE_FILE_VALIDATION_FAILED:Number = -270;
+ private var ERROR_CODE_FILE_CANCELLED:Number = -280;
+ private var ERROR_CODE_UPLOAD_STOPPED:Number = -290;
+ private var ERROR_CODE_RESIZE:Number = -300;
+
+
+ // Button Actions
+ private var BUTTON_ACTION_SELECT_FILE:Number = -100;
+ private var BUTTON_ACTION_SELECT_FILES:Number = -110;
+ private var BUTTON_ACTION_START_UPLOAD:Number = -120;
+ private var BUTTON_ACTION_NONE:Number = -130;
+ private var BUTTON_ACTION_JAVASCRIPT:Number = -130; // DEPRECATED
+
+ private var BUTTON_CURSOR_ARROW:Number = -1;
+ private var BUTTON_CURSOR_HAND:Number = -2;
+
+ // Resize encoder
+ private var ENCODER_JPEG:Number = -1;
+ private var ENCODER_PNG:Number = -2;
+
+ public function SWFUpload() {
+ // Do the feature detection. Make sure this version of Flash supports the features we need. If not
+ // abort initialization.
+ if (!flash.net.FileReferenceList || !flash.net.FileReference || !flash.net.URLRequest || !flash.external.ExternalInterface || !flash.external.ExternalInterface.available || !DataEvent.UPLOAD_COMPLETE_DATA) {
+ return;
+ }
+
+ var self:SWFUpload = this;
+ Security.allowDomain("*"); // Allow uploading to any domain
+ Security.allowInsecureDomain("*"); // Allow uploading from HTTP to HTTPS and HTTPS to HTTP
+
+ // Keep Flash Player busy so it doesn't show the "flash script is running slowly" error
+ var counter:Number = 0;
+ root.addEventListener(Event.ENTER_FRAME, function ():void { if (++counter > 100) counter = 0; });
+
+ // Setup file FileReferenceList events
+ this.fileBrowserMany.addEventListener(Event.SELECT, this.Select_Many_Handler);
+ this.fileBrowserMany.addEventListener(Event.CANCEL, this.DialogCancelled_Handler);
+
+
+ this.stage.align = StageAlign.TOP_LEFT;
+ this.stage.scaleMode = StageScaleMode.NO_SCALE;
+ this.stage.addEventListener(Event.RESIZE, function (e:Event):void {
+ self.HandleStageResize(e);
+ });
+
+ // Setup the button and text label
+ this.buttonLoader = new Loader();
+ var doNothing:Function = function ():void { };
+ this.buttonLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, doNothing );
+ this.buttonLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, doNothing );
+ this.buttonLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.ButtonImageLoaded );
+ this.stage.addChild(this.buttonLoader);
+
+ this.stage.addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void {
+ self.UpdateButtonState();
+ self.ButtonClickHandler(event);
+ });
+ this.stage.addEventListener(MouseEvent.MOUSE_DOWN, function (event:MouseEvent):void {
+ self.buttonStateMouseDown = true;
+ self.UpdateButtonState();
+ });
+ this.stage.addEventListener(MouseEvent.MOUSE_UP, function (event:MouseEvent):void {
+ self.buttonStateMouseDown = false;
+ self.UpdateButtonState();
+ });
+ this.stage.addEventListener(MouseEvent.MOUSE_OVER, function (event:MouseEvent):void {
+ self.buttonStateMouseDown = event.buttonDown;
+ self.buttonStateOver = true;
+ self.UpdateButtonState();
+ ExternalCall.Simple(self.mouseOver_Callback);
+ });
+ this.stage.addEventListener(MouseEvent.MOUSE_OUT, function (event:MouseEvent):void {
+ self.buttonStateMouseDown = false;
+ self.buttonStateOver = false;
+ self.UpdateButtonState();
+ });
+ // Handle the mouse leaving the flash movie altogether
+ this.stage.addEventListener(Event.MOUSE_LEAVE, function (event:Event):void {
+ self.buttonStateMouseDown = false;
+ self.buttonStateOver = false;
+ self.UpdateButtonState();
+ ExternalCall.Simple(self.mouseOut_Callback);
+ });
+
+ this.buttonTextField = new TextField();
+ this.buttonTextField.type = TextFieldType.DYNAMIC;
+ this.buttonTextField.antiAliasType = AntiAliasType.ADVANCED;
+ this.buttonTextField.autoSize = TextFieldAutoSize.NONE;
+ this.buttonTextField.cacheAsBitmap = true;
+ this.buttonTextField.multiline = true;
+ this.buttonTextField.wordWrap = false;
+ this.buttonTextField.tabEnabled = false;
+ this.buttonTextField.background = false;
+ this.buttonTextField.border = false;
+ this.buttonTextField.selectable = false;
+ this.buttonTextField.condenseWhite = true;
+
+ this.stage.addChild(this.buttonTextField);
+
+
+ this.buttonCursorSprite = new Sprite();
+ this.buttonCursorSprite.graphics.beginFill(0xFFFFFF, 0);
+ this.buttonCursorSprite.graphics.drawRect(0, 0, 1, 1);
+ this.buttonCursorSprite.graphics.endFill();
+ this.buttonCursorSprite.buttonMode = true;
+ this.buttonCursorSprite.x = 0;
+ this.buttonCursorSprite.y = 0;
+ this.buttonCursorSprite.addEventListener(MouseEvent.CLICK, doNothing);
+ this.stage.addChild(this.buttonCursorSprite);
+
+ this.sizeTimer = new Timer(10, 0);
+ this.sizeTimer.addEventListener(TimerEvent.TIMER, function ():void {
+ //self.Debug("Stage:" + self.stage.stageWidth + " by " + self.stage.stageHeight);
+ if (self.stage.stageWidth > 0 || self.stage.stageHeight > 0) {
+ self.HandleStageResize(null);
+ self.sizeTimer.stop();
+ self.sizeTimer.removeEventListener(TimerEvent.TIMER, arguments.callee);
+ self.sizeTimer = null;
+ }
+ } );
+ this.sizeTimer.start();
+
+ // Get the movie name
+ this.movieName = decodeURIComponent(root.loaderInfo.parameters.movieName);
+
+ // **Configure the callbacks**
+ // The JavaScript tracks all the instances of SWFUpload on a page. We can access the instance
+ // associated with this SWF file using the movieName. Each callback is accessible by making
+ // a call directly to it on our instance. There is no error handling for undefined callback functions.
+ // A developer would have to deliberately remove the default functions,set the variable to null, or remove
+ // it from the init function.
+ this.flashReady_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].flashReady";
+ this.fileDialogStart_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].fileDialogStart";
+ this.fileQueued_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].fileQueued";
+ this.fileQueueError_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].fileQueueError";
+ this.fileDialogComplete_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].fileDialogComplete";
+
+ this.uploadResizeStart_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].uploadResizeStart";
+ this.uploadStart_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].uploadStart";
+ this.uploadProgress_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].uploadProgress";
+ this.uploadError_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].uploadError";
+ this.uploadSuccess_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].uploadSuccess";
+
+ this.uploadComplete_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].uploadComplete";
+
+ this.debug_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].debug";
+
+ this.mouseOut_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].mouseOut";
+ this.mouseOver_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].mouseOver";
+ this.mouseClick_Callback = "SWFUpload.instances[\"" + this.movieName + "\"].mouseClick";
+
+ // Get the Flash Vars
+ this.uploadURL = decodeURIComponent(root.loaderInfo.parameters.uploadURL);
+ this.filePostName = decodeURIComponent(root.loaderInfo.parameters.filePostName);
+ this.fileTypes = decodeURIComponent(root.loaderInfo.parameters.fileTypes);
+ this.fileTypesDescription = decodeURIComponent(root.loaderInfo.parameters.fileTypesDescription) + " (" + this.fileTypes + ")";
+ this.loadPostParams(decodeURIComponent(root.loaderInfo.parameters.params));
+
+
+ if (!this.filePostName) {
+ this.filePostName = "Filedata";
+ }
+ if (!this.fileTypes) {
+ this.fileTypes = "*.*";
+ }
+ if (!this.fileTypesDescription) {
+ this.fileTypesDescription = "All Files";
+ }
+
+ this.LoadFileExensions(this.fileTypes);
+
+ try {
+ this.debugEnabled = decodeURIComponent(root.loaderInfo.parameters.debugEnabled) == "true" ? true : false;
+ } catch (ex:Object) {
+ this.debugEnabled = false;
+ }
+
+ try {
+ this.SetFileSizeLimit(String(decodeURIComponent(root.loaderInfo.parameters.fileSizeLimit)));
+ } catch (ex:Object) {
+ this.fileSizeLimit = 0;
+ }
+
+
+ try {
+ this.fileUploadLimit = Number(decodeURIComponent(root.loaderInfo.parameters.fileUploadLimit));
+ if (this.fileUploadLimit < 0) this.fileUploadLimit = 0;
+ } catch (ex:Object) {
+ this.fileUploadLimit = 0;
+ }
+
+ try {
+ this.fileQueueLimit = Number(decodeURIComponent(root.loaderInfo.parameters.fileQueueLimit));
+ if (this.fileQueueLimit < 0) this.fileQueueLimit = 0;
+ } catch (ex:Object) {
+ this.fileQueueLimit = 0;
+ }
+
+ // Set the queue limit to match the upload limit when the queue limit is bigger than the upload limit
+ if (this.fileQueueLimit > this.fileUploadLimit && this.fileUploadLimit != 0) this.fileQueueLimit = this.fileUploadLimit;
+ // The the queue limit is unlimited and the upload limit is not then set the queue limit to the upload limit
+ if (this.fileQueueLimit == 0 && this.fileUploadLimit != 0) this.fileQueueLimit = this.fileUploadLimit;
+
+ try {
+ this.useQueryString = decodeURIComponent(root.loaderInfo.parameters.useQueryString) == "true" ? true : false;
+ } catch (ex:Object) {
+ this.useQueryString = false;
+ }
+
+ try {
+ this.requeueOnError = decodeURIComponent(root.loaderInfo.parameters.requeueOnError) == "true" ? true : false;
+ } catch (ex:Object) {
+ this.requeueOnError = false;
+ }
+
+ try {
+ this.SetHTTPSuccess(String(decodeURIComponent(root.loaderInfo.parameters.httpSuccess)));
+ } catch (ex:Object) {
+ this.SetHTTPSuccess([]);
+ }
+
+ try {
+ this.SetAssumeSuccessTimeout(Number(decodeURIComponent(root.loaderInfo.parameters.assumeSuccessTimeout)));
+ } catch (ex:Object) {
+ this.SetAssumeSuccessTimeout(0);
+ }
+
+ try {
+ this.SetButtonImageURL(String(decodeURIComponent(root.loaderInfo.parameters.buttonImageURL)));
+ } catch (ex:Object) {
+ this.SetButtonImageURL("");
+ }
+
+ try {
+ this.SetButtonText(String(decodeURIComponent(root.loaderInfo.parameters.buttonText)));
+ } catch (ex:Object) {
+ this.SetButtonText("");
+ }
+
+ try {
+ this.SetButtonTextPadding(Number(decodeURIComponent(root.loaderInfo.parameters.buttonTextLeftPadding)), Number(decodeURIComponent(root.loaderInfo.parameters.buttonTextTopPadding)));
+ } catch (ex:Object) {
+ this.SetButtonTextPadding(0, 0);
+ }
+
+ try {
+ this.SetButtonTextStyle(String(decodeURIComponent(root.loaderInfo.parameters.buttonTextStyle)));
+ } catch (ex:Object) {
+ this.SetButtonTextStyle("");
+ }
+
+ try {
+ this.SetButtonAction(Number(decodeURIComponent(root.loaderInfo.parameters.buttonAction)));
+ } catch (ex:Object) {
+ this.SetButtonAction(this.BUTTON_ACTION_SELECT_FILES);
+ }
+
+ try {
+ this.SetButtonDisabled(decodeURIComponent(root.loaderInfo.parameters.buttonDisabled) == "true" ? true : false);
+ } catch (ex:Object) {
+ this.SetButtonDisabled(Boolean(false));
+ }
+
+ try {
+ this.SetButtonCursor(Number(decodeURIComponent(root.loaderInfo.parameters.buttonCursor)));
+ } catch (ex:Object) {
+ this.SetButtonCursor(this.BUTTON_CURSOR_ARROW);
+ }
+
+ this.SetupExternalInterface();
+
+ this.Debug("SWFUpload Init Complete");
+ this.PrintDebugInfo();
+
+ ExternalCall.Simple(this.flashReady_Callback);
+ this.hasCalledFlashReady = true;
+ }
+
+ private function HandleStageResize(e:Event):void {
+ if (this.stage.stageWidth > 0 || this.stage.stageHeight > 0) {
+ this.Debug("Stage Resize:" + this.stage.stageWidth + " by " + this.stage.stageHeight);
+
+ // scale the button (if it's not loaded don't crash)
+ try {
+ var buttonHeight:Number = this.buttonLoader.contentLoaderInfo.height / 4;
+ this.buttonLoader.height = this.stage.stageHeight * 4;
+ this.buttonLoader.scaleX = this.buttonLoader.scaleY;
+ } catch (ex:Error) { }
+
+ // Scale the button cursor
+ try {
+ this.buttonCursorSprite.width = this.stage.stageWidth;
+ this.buttonCursorSprite.height = this.stage.stageHeight;
+ } catch (ex:Error) {}
+
+ // scale the text area (it doesn't resize but it still needs to fit)
+ try {
+ this.buttonTextField.width = this.stage.stageWidth;
+ this.buttonTextField.height = this.stage.stageHeight;
+ } catch (ex:Error) {}
+ }
+ }
+
+ private function SetupExternalInterface():void {
+ try {
+ ExternalInterface.addCallback("SelectFile", this.SelectFile);
+ ExternalInterface.addCallback("SelectFiles", this.SelectFiles);
+ ExternalInterface.addCallback("StartUpload", this.StartUpload);
+ ExternalInterface.addCallback("ReturnUploadStart", this.ReturnUploadStart);
+ ExternalInterface.addCallback("StopUpload", this.StopUpload);
+ ExternalInterface.addCallback("CancelUpload", this.CancelUpload);
+ ExternalInterface.addCallback("RequeueUpload", this.RequeueUpload);
+
+ ExternalInterface.addCallback("GetStats", this.GetStats);
+ ExternalInterface.addCallback("SetStats", this.SetStats);
+ ExternalInterface.addCallback("GetFile", this.GetFile);
+ ExternalInterface.addCallback("GetFileByIndex", this.GetFileByIndex);
+ ExternalInterface.addCallback("GetFileByQueueIndex", this.GetFileByQueueIndex);
+
+ ExternalInterface.addCallback("AddFileParam", this.AddFileParam);
+ ExternalInterface.addCallback("RemoveFileParam", this.RemoveFileParam);
+
+ ExternalInterface.addCallback("SetUploadURL", this.SetUploadURL);
+ ExternalInterface.addCallback("SetPostParams", this.SetPostParams);
+ ExternalInterface.addCallback("SetFileTypes", this.SetFileTypes);
+ ExternalInterface.addCallback("SetFileSizeLimit", this.SetFileSizeLimit);
+ ExternalInterface.addCallback("SetFileUploadLimit", this.SetFileUploadLimit);
+ ExternalInterface.addCallback("SetFileQueueLimit", this.SetFileQueueLimit);
+ ExternalInterface.addCallback("SetFilePostName", this.SetFilePostName);
+ ExternalInterface.addCallback("SetUseQueryString", this.SetUseQueryString);
+ ExternalInterface.addCallback("SetRequeueOnError", this.SetRequeueOnError);
+ ExternalInterface.addCallback("SetHTTPSuccess", this.SetHTTPSuccess);
+ ExternalInterface.addCallback("SetAssumeSuccessTimeout", this.SetAssumeSuccessTimeout);
+ ExternalInterface.addCallback("SetDebugEnabled", this.SetDebugEnabled);
+
+ ExternalInterface.addCallback("SetButtonImageURL", this.SetButtonImageURL);
+ ExternalInterface.addCallback("SetButtonText", this.SetButtonText);
+ ExternalInterface.addCallback("SetButtonTextPadding", this.SetButtonTextPadding);
+ ExternalInterface.addCallback("SetButtonTextStyle", this.SetButtonTextStyle);
+ ExternalInterface.addCallback("SetButtonAction", this.SetButtonAction);
+ ExternalInterface.addCallback("SetButtonDisabled", this.SetButtonDisabled);
+ ExternalInterface.addCallback("SetButtonCursor", this.SetButtonCursor);
+ } catch (ex:Error) {
+ this.Debug("Callbacks where not set: " + ex.message);
+ return;
+ }
+ }
+
+ /* *****************************************
+ * FileReference Event Handlers
+ * *************************************** */
+ private function DialogCancelled_Handler(event:Event):void {
+ this.Debug("Event: fileDialogComplete: File Dialog window cancelled.");
+ ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, 0, 0, this.queued_uploads);
+ }
+
+ private function Open_Handler(event:Event):void {
+ this.Debug("Event: uploadProgress (OPEN): File ID: " + this.current_file_item.id);
+ this.current_file_item.finalUploadProgress = false;
+ ExternalCall.UploadProgress(this.uploadProgress_Callback, this.current_file_item.ToJavaScriptObject(), 0, this.current_file_item.file_reference.size);
+ }
+
+ private function FileProgress_Handler(event:ProgressEvent):void {
+ // On early than Mac OS X 10.3 bytesLoaded is always -1, convert this to zero. Do bytesTotal for good measure.
+ // http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html#event:progress
+ var bytesLoaded:Number = event.bytesLoaded < 0 ? 0 : event.bytesLoaded;
+ var bytesTotal:Number = event.bytesTotal < 0 ? 0 : event.bytesTotal;
+
+ // Because Flash never fires a complete event if the server doesn't respond after 30 seconds or on Macs if there
+ // is no content in the response we'll set a timer and assume that the upload is successful after the defined amount of
+ // time. If the timeout is zero then we won't use the timer.
+ if (bytesLoaded === bytesTotal) {
+ this.current_file_item.finalUploadProgress = true;
+ if (bytesTotal > 0 && this.assumeSuccessTimeout > 0) {
+ if (this.assumeSuccessTimer !== null) {
+ this.assumeSuccessTimer.stop();
+ this.assumeSuccessTimer = null;
+ }
+
+ this.assumeSuccessTimer = new Timer(this.assumeSuccessTimeout * 1000, 1);
+ this.assumeSuccessTimer.addEventListener(TimerEvent.TIMER_COMPLETE, AssumeSuccessTimer_Handler);
+ this.assumeSuccessTimer.start();
+ }
+ }
+
+ this.Debug("Event: uploadProgress: File ID: " + this.current_file_item.id + ". Bytes: " + bytesLoaded + ". Total: " + bytesTotal);
+ ExternalCall.UploadProgress(this.uploadProgress_Callback, this.current_file_item.ToJavaScriptObject(), bytesLoaded, bytesTotal);
+ }
+
+ private function AssumeSuccessTimer_Handler(event:TimerEvent):void {
+ this.Debug("Event: AssumeSuccess: " + this.assumeSuccessTimeout + " passed without server response");
+ this.UploadSuccess(this.current_file_item, "", false);
+ }
+
+ private function Complete_Handler(event:Event):void {
+ /* Because we can't do COMPLETE or DATA events (we have to do both) we can't
+ * just call uploadSuccess from the complete handler, we have to wait for
+ * the Data event which may never come. However, testing shows it always comes
+ * within a couple milliseconds if it is going to come so the solution is:
+ *
+ * Set a timer in the COMPLETE event (which always fires) and if DATA is fired
+ * it will stop the timer and call uploadComplete
+ *
+ * If the timer expires then DATA won't be fired and we call uploadComplete
+ * */
+
+ // Set the timer
+ if (serverDataTimer != null) {
+ this.serverDataTimer.stop();
+ this.serverDataTimer = null;
+ }
+
+ this.serverDataTimer = new Timer(100, 1);
+ //var self:SWFUpload = this;
+ this.serverDataTimer.addEventListener(TimerEvent.TIMER, this.ServerDataTimer_Handler);
+ this.serverDataTimer.start();
+ }
+ private function ServerDataTimer_Handler(event:TimerEvent):void {
+ this.UploadSuccess(this.current_file_item, "");
+ }
+
+ private function ServerData_Handler(event:DataEvent):void {
+ this.UploadSuccess(this.current_file_item, event.data);
+ }
+
+ private function UploadSuccess(file:FileItem, serverData:String, responseReceived:Boolean = true):void {
+ if (this.serverDataTimer !== null) {
+ this.serverDataTimer.stop();
+ this.serverDataTimer = null;
+ }
+ if (this.assumeSuccessTimer !== null) {
+ this.assumeSuccessTimer.stop();
+ this.assumeSuccessTimer = null;
+ }
+
+ // If the 100% upload progress hasn't been called then call it now
+ if (!file.finalUploadProgress) {
+ file.finalUploadProgress = true;
+ this.Debug("Event: uploadProgress (simulated 100%): File ID: " + file.id + ". Bytes: " + file.file_reference.size + ". Total: " + file.file_reference.size);
+ ExternalCall.UploadProgress(this.uploadProgress_Callback, file.ToJavaScriptObject(), file.file_reference.size, file.file_reference.size);
+ }
+
+ this.successful_uploads++;
+ file.file_status = FileItem.FILE_STATUS_SUCCESS;
+
+ this.Debug("Event: uploadSuccess: File ID: " + file.id + " Response Received: " + responseReceived.toString() + " Data: " + serverData);
+ ExternalCall.UploadSuccess(this.uploadSuccess_Callback, file.ToJavaScriptObject(), serverData, responseReceived);
+
+ this.UploadComplete(false);
+
+ }
+
+ private function HTTPError_Handler(event:HTTPStatusEvent):void {
+ var isSuccessStatus:Boolean = false;
+ for (var i:Number = 0; i < this.httpSuccess.length; i++) {
+ if (this.httpSuccess[i] === event.status) {
+ isSuccessStatus = true;
+ break;
+ }
+ }
+
+
+ if (isSuccessStatus) {
+ this.Debug("Event: httpError: Translating status code " + event.status + " to uploadSuccess");
+
+ var serverDataEvent:DataEvent = new DataEvent(DataEvent.UPLOAD_COMPLETE_DATA, event.bubbles, event.cancelable, "");
+ this.ServerData_Handler(serverDataEvent);
+ } else {
+ this.upload_errors++;
+ this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
+
+ this.Debug("Event: uploadError: HTTP ERROR : File ID: " + this.current_file_item.id + ". HTTP Status: " + event.status + ".");
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_HTTP_ERROR, this.current_file_item.ToJavaScriptObject(), event.status.toString());
+ this.UploadComplete(true); // An IO Error is also called so we don't want to complete the upload yet.
+ }
+ }
+
+ // Note: Flash Player does not support Uploads that require authentication. Attempting this will trigger an
+ // IO Error or it will prompt for a username and password and may crash the browser (FireFox/Opera)
+ private function IOError_Handler(event:IOErrorEvent):void {
+ // Only trigger an IO Error event if we haven't already done an HTTP error
+ if (this.current_file_item.file_status != FileItem.FILE_STATUS_ERROR) {
+ this.upload_errors++;
+ this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
+
+ this.Debug("Event: uploadError : IO Error : File ID: " + this.current_file_item.id + ". IO Error: " + event.text);
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_IO_ERROR, this.current_file_item.ToJavaScriptObject(), event.text);
+ }
+
+ this.UploadComplete(true);
+ }
+
+ private function SecurityError_Handler(event:SecurityErrorEvent):void {
+ this.upload_errors++;
+ this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
+
+ this.Debug("Event: uploadError : Security Error : File Number: " + this.current_file_item.id + ". Error text: " + event.text);
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_SECURITY_ERROR, this.current_file_item.ToJavaScriptObject(), event.text);
+
+ this.UploadComplete(true);
+ }
+
+ private function Select_Many_Handler(event:Event):void {
+ this.Select_Handler(this.fileBrowserMany.fileList);
+ }
+ private function Select_One_Handler(event:Event):void {
+ var fileArray:Array = new Array(1);
+ fileArray[0] = this.fileBrowserOne;
+ this.Select_Handler(fileArray);
+ }
+
+ private function Select_Handler(file_reference_list:Array):void {
+ this.Debug("Select Handler: Received the files selected from the dialog. Processing the file list...");
+
+ var num_files_queued:Number = 0;
+
+ // Determine how many queue slots are remaining (check the unlimited (0) settings, successful uploads and queued uploads)
+ var queue_slots_remaining:Number = 0;
+ if (this.fileUploadLimit == 0) {
+ queue_slots_remaining = this.fileQueueLimit == 0 ? file_reference_list.length : (this.fileQueueLimit - this.queued_uploads); // If unlimited queue make the allowed size match however many files were selected.
+ } else {
+ var remaining_uploads:Number = this.fileUploadLimit - this.successful_uploads - this.queued_uploads;
+ if (remaining_uploads < 0) remaining_uploads = 0;
+ if (this.fileQueueLimit == 0 || this.fileQueueLimit >= remaining_uploads) {
+ queue_slots_remaining = remaining_uploads;
+ } else if (this.fileQueueLimit < remaining_uploads) {
+ queue_slots_remaining = this.fileQueueLimit - this.queued_uploads;
+ }
+ }
+
+ if (queue_slots_remaining < 0) queue_slots_remaining = 0;
+
+ // Check if the number of files selected is greater than the number allowed to queue up.
+ if (queue_slots_remaining < file_reference_list.length) {
+ this.Debug("Event: fileQueueError : Selected Files (" + file_reference_list.length + ") exceeds remaining Queue size (" + queue_slots_remaining + ").");
+ ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_QUEUE_LIMIT_EXCEEDED, null, queue_slots_remaining.toString());
+ } else {
+ // Process each selected file
+ for (var i:Number = 0; i < file_reference_list.length; i++) {
+ var file_item:FileItem = new FileItem(file_reference_list[i], this.movieName, this.file_index.length);
+ this.file_index[file_item.index] = file_item;
+
+ // Verify that the file is accessible. Zero byte files and possibly other conditions can cause a file to be inaccessible.
+ var jsFileObj:Object = file_item.ToJavaScriptObject();
+ var is_valid_file_reference:Boolean = (jsFileObj.filestatus !== FileItem.FILE_STATUS_ERROR);
+
+ if (is_valid_file_reference) {
+ // Check the size, if it's within the limit add it to the upload list.
+ var size_result:Number = this.CheckFileSize(file_item);
+ var is_valid_filetype:Boolean = this.CheckFileType(file_item);
+ if(size_result == this.SIZE_OK && is_valid_filetype) {
+ file_item.file_status = FileItem.FILE_STATUS_QUEUED;
+ this.file_queue.push(file_item);
+ this.queued_uploads++;
+ num_files_queued++;
+ this.Debug("Event: fileQueued : File ID: " + file_item.id);
+ ExternalCall.FileQueued(this.fileQueued_Callback, file_item.ToJavaScriptObject());
+ }
+ else if (!is_valid_filetype) {
+ //file_item.file_reference = null; // Cleanup the object
+ file_item.file_status = FileItem.FILE_STATUS_ERROR;
+ this.queue_errors++;
+ this.Debug("Event: fileQueueError : File not of a valid type.");
+ ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_INVALID_FILETYPE, file_item.ToJavaScriptObject(), "File is not an allowed file type.");
+ }
+ else if (size_result == this.SIZE_TOO_BIG) {
+ //file_item.file_reference = null; // Cleanup the object
+ file_item.file_status = FileItem.FILE_STATUS_ERROR;
+ this.queue_errors++;
+ this.Debug("Event: fileQueueError : File exceeds size limit.");
+ ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT, file_item.ToJavaScriptObject(), "File size exceeds allowed limit.");
+ }
+ else if (size_result == this.SIZE_ZERO_BYTE) {
+ file_item.file_reference = null; // Cleanup the object
+ file_item.file_status = FileItem.FILE_STATUS_ERROR;
+ this.queue_errors++;
+ this.Debug("Event: fileQueueError : File is zero bytes.");
+ ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_ZERO_BYTE_FILE, file_item.ToJavaScriptObject(), "File is zero bytes and cannot be uploaded.");
+ }
+ } else {
+ file_item.file_reference = null; // Cleanup the object
+ file_item.file_status = FileItem.FILE_STATUS_ERROR;
+ this.queue_errors++;
+ this.Debug("Event: fileQueueError : File is zero bytes or FileReference is invalid.");
+ ExternalCall.FileQueueError(this.fileQueueError_Callback, this.ERROR_CODE_ZERO_BYTE_FILE, file_item.ToJavaScriptObject(), "File is zero bytes or cannot be accessed and cannot be uploaded.");
+ }
+ }
+ }
+
+ this.Debug("Event: fileDialogComplete : Finished processing selected files. Files selected: " + file_reference_list.length + ". Files Queued: " + num_files_queued);
+ ExternalCall.FileDialogComplete(this.fileDialogComplete_Callback, file_reference_list.length, num_files_queued, this.queued_uploads);
+ }
+
+ /* ****************************************************************
+ Externally exposed functions
+ ****************************************************************** */
+ // Opens a file browser dialog that allows one file to be selected.
+ private function SelectFile():void {
+ this.fileBrowserOne = new FileReference();
+ this.fileBrowserOne.addEventListener(Event.SELECT, this.Select_One_Handler);
+ this.fileBrowserOne.addEventListener(Event.CANCEL, this.DialogCancelled_Handler);
+
+ // Default file type settings
+ var allowed_file_types:String = "*.*";
+ var allowed_file_types_description:String = "All Files";
+
+ // Get the instance settings
+ if (this.fileTypes.length > 0) allowed_file_types = this.fileTypes;
+ if (this.fileTypesDescription.length > 0) allowed_file_types_description = this.fileTypesDescription;
+
+ this.Debug("Event: fileDialogStart : Browsing files. Single Select. Allowed file types: " + allowed_file_types);
+ ExternalCall.Simple(this.fileDialogStart_Callback);
+
+ try {
+ this.fileBrowserOne.browse([new FileFilter(allowed_file_types_description, allowed_file_types)]);
+ } catch (ex:Error) {
+ this.Debug("Exception: " + ex.toString());
+ }
+ }
+
+ // Opens a file browser dialog that allows multiple files to be selected.
+ private function SelectFiles():void {
+ var allowed_file_types:String = "*.*";
+ var allowed_file_types_description:String = "All Files";
+
+ if (this.fileTypes.length > 0) allowed_file_types = this.fileTypes;
+ if (this.fileTypesDescription.length > 0) allowed_file_types_description = this.fileTypesDescription;
+
+ this.Debug("Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: " + allowed_file_types);
+ ExternalCall.Simple(this.fileDialogStart_Callback);
+
+ try {
+ this.fileBrowserMany.browse([new FileFilter(allowed_file_types_description, allowed_file_types)]);
+ } catch (ex:Error) {
+ this.Debug("Exception: " + ex.toString());
+ }
+ }
+
+
+ // Cancel the current upload and stops. Doesn't advance the upload pointer. The current file is requeued at the beginning.
+ private function StopUpload():void {
+ if (this.current_file_item != null) {
+ // Cancel the upload and re-queue the FileItem
+ if (this.current_file_item.upload_type === FileItem.UPLOAD_TYPE_NORMAL) {
+ this.current_file_item.file_reference.cancel();
+ } else {
+ if (this.current_file_item.resized_uploader != null) {
+ this.current_file_item.resized_uploader.cancel();
+ this.current_file_item.resized_uploader = null;
+ }
+ }
+
+ // Remove the event handlers
+ this.removeEventListeners(this.current_file_item);
+
+ this.current_file_item.upload_type = FileItem.UPLOAD_TYPE_NORMAL;
+ this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
+ this.file_queue.unshift(this.current_file_item);
+ var js_object:Object = this.current_file_item.ToJavaScriptObject();
+ this.current_file_item = null;
+
+ this.Debug("Event: uploadError: upload stopped. File ID: " + js_object.ID);
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_UPLOAD_STOPPED, js_object, "Upload Stopped");
+ this.Debug("Event: uploadComplete. File ID: " + js_object.ID);
+ ExternalCall.UploadComplete(this.uploadComplete_Callback, js_object);
+
+ this.Debug("StopUpload(): upload stopped.");
+ } else {
+ this.Debug("StopUpload(): No file is currently uploading. Nothing to do.");
+ }
+ }
+
+ /* Cancels the upload specified by file_id
+ * If the file is currently uploading it is cancelled and the uploadComplete
+ * event gets called.
+ * If the file is not currently uploading then only the uploadCancelled event is fired.
+ *
+ * The triggerComplete is used by the resize stuff to cancel the upload
+ * */
+ private function CancelUpload(file_id:String, triggerErrorEvent:Boolean = true):void {
+ var file_item:FileItem = null;
+ // Check the current file item
+ if (this.current_file_item != null && (this.current_file_item.id == file_id || !file_id)) {
+ if (this.current_file_item.upload_type === FileItem.UPLOAD_TYPE_NORMAL) {
+ this.current_file_item.file_reference.cancel();
+ } else {
+ if (this.current_file_item.resized_uploader != null) {
+ this.current_file_item.resized_uploader.cancel();
+ this.current_file_item.resized_uploader = null;
+ }
+ }
+ this.current_file_item.file_status = FileItem.FILE_STATUS_CANCELLED;
+ this.current_file_item.upload_type = FileItem.UPLOAD_TYPE_NORMAL;
+ this.upload_cancelled++;
+
+ if (triggerErrorEvent) {
+ this.Debug("Event: uploadError: File ID: " + this.current_file_item.id + ". Cancelled current upload");
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, this.current_file_item.ToJavaScriptObject(), "File Upload Cancelled.");
+ } else {
+ this.Debug("Event: cancelUpload: File ID: " + this.current_file_item.id + ". Cancelled current upload. Suppressed uploadError event.");
+ }
+
+ this.UploadComplete(false);
+ } else if (file_id) {
+ // Find the file in the queue
+ var file_index:Number = this.FindIndexInFileQueue(file_id);
+ if (file_index >= 0) {
+ // Remove the file from the queue
+ file_item = FileItem(this.file_queue[file_index]);
+ file_item.file_status = FileItem.FILE_STATUS_CANCELLED;
+ this.file_queue.splice(file_index, 1);
+ this.queued_uploads--;
+ this.upload_cancelled++;
+
+ // Cancel the file (just for good measure) and make the callback
+ if (file_item.upload_type === FileItem.UPLOAD_TYPE_NORMAL) {
+ file_item.file_reference.cancel();
+ } else {
+ if (file_item.resized_uploader != null) {
+ file_item.resized_uploader.cancel();
+ file_item.resized_uploader = null;
+ }
+ }
+ this.removeEventListeners(file_item);
+ file_item.upload_type = FileItem.UPLOAD_TYPE_NORMAL;
+
+
+ if (triggerErrorEvent) {
+ this.Debug("Event: uploadError : " + file_item.id + ". Cancelled queued upload");
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, file_item.ToJavaScriptObject(), "File Cancelled");
+ } else {
+ this.Debug("Event: cancelUpload: File ID: " + file_item.id + ". Cancelled current upload. Suppressed uploadError event.");
+ }
+
+ // Get rid of the file object
+ file_item = null;
+ }
+ } else {
+ // Get the first file and cancel it
+ while (this.file_queue.length > 0 && file_item == null) {
+ // Check that File Reference is valid (if not make sure it's deleted and get the next one on the next loop)
+ file_item = FileItem(this.file_queue.shift()); // Cast back to a FileItem
+ if (typeof(file_item) == "undefined") {
+ file_item = null;
+ continue;
+ }
+ }
+
+ if (file_item != null) {
+ file_item.file_status = FileItem.FILE_STATUS_CANCELLED;
+ this.queued_uploads--;
+ this.upload_cancelled++;
+
+
+ // Cancel the file (just for good measure) and make the callback
+ if (file_item.upload_type === FileItem.UPLOAD_TYPE_NORMAL) {
+ file_item.file_reference.cancel();
+ } else {
+ if (file_item.resized_uploader != null) {
+ file_item.resized_uploader.cancel();
+ file_item.resized_uploader = null;
+ }
+ }
+
+ this.removeEventListeners(file_item);
+ file_item.upload_type = FileItem.UPLOAD_TYPE_NORMAL;
+
+ if (triggerErrorEvent) {
+ this.Debug("Event: uploadError : " + file_item.id + ". Cancelled queued upload");
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_CANCELLED, file_item.ToJavaScriptObject(), "File Cancelled");
+ } else {
+ this.Debug("Event: cancelUpload: File ID: " + file_item.id + ". Cancelled current upload. Suppressed uploadError event.");
+ }
+
+ // Get rid of the file object
+ file_item = null;
+ }
+
+ }
+
+ }
+
+ /* Requeues the indicated file. Returns true if successful or if the file is
+ * already in the queue. Otherwise returns false.
+ * */
+ private function RequeueUpload(fileIdentifier:*):Boolean {
+ var file:FileItem = null;
+ if (typeof(fileIdentifier) === "number") {
+ var fileIndex:Number = Number(fileIdentifier);
+ if (fileIndex >= 0 && fileIndex < this.file_index.length) {
+ file = this.file_index[fileIndex];
+ }
+ } else if (typeof(fileIdentifier) === "string") {
+ file = FindFileInFileIndex(String(fileIdentifier));
+ } else {
+ return false;
+ }
+
+ if (file !== null && file.file_reference !== null) {
+ if (file.file_status === FileItem.FILE_STATUS_IN_PROGRESS || file.file_status === FileItem.FILE_STATUS_NEW) {
+ return false;
+ } else if (file.file_status !== FileItem.FILE_STATUS_QUEUED) {
+ file.file_status = FileItem.FILE_STATUS_QUEUED;
+ this.file_queue.unshift(file);
+ this.queued_uploads++;
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ private function GetStats():Object {
+ return {
+ in_progress : this.current_file_item == null ? 0 : 1,
+ files_queued : this.queued_uploads,
+ successful_uploads : this.successful_uploads,
+ upload_errors : this.upload_errors,
+ upload_cancelled : this.upload_cancelled,
+ queue_errors : this.queue_errors
+ };
+ }
+ private function SetStats(stats:Object):void {
+ this.successful_uploads = typeof(stats["successful_uploads"]) === "number" ? stats["successful_uploads"] : this.successful_uploads;
+ this.upload_errors = typeof(stats["upload_errors"]) === "number" ? stats["upload_errors"] : this.upload_errors;
+ this.upload_cancelled = typeof(stats["upload_cancelled"]) === "number" ? stats["upload_cancelled"] : this.upload_cancelled;
+ this.queue_errors = typeof(stats["queue_errors"]) === "number" ? stats["queue_errors"] : this.queue_errors;
+ }
+
+ private function GetFile(file_id:String):Object {
+ var file_index:Number = this.FindIndexInFileQueue(file_id);
+ if (file_index >= 0) {
+ var file:FileItem = this.file_queue[file_index];
+ } else {
+ if (this.current_file_item != null) {
+ file = this.current_file_item;
+ } else {
+ for (var i:Number = 0; i < this.file_queue.length; i++) {
+ file = this.file_queue[i];
+ if (file != null) break;
+ }
+ }
+ }
+
+ if (file == null) {
+ return null;
+ } else {
+ return file.ToJavaScriptObject();
+ }
+
+ }
+
+ private function GetFileByIndex(index:Number):Object {
+ if (index < 0 || index > this.file_index.length - 1) {
+ return null;
+ } else {
+ return this.file_index[index].ToJavaScriptObject();
+ }
+ }
+
+ private function GetFileByQueueIndex(index:Number):Object {
+ if (index < 0 || index > this.file_queue.length - 1) {
+ return null;
+ } else {
+ return this.file_queue[index].ToJavaScriptObject();
+ }
+ }
+
+ private function AddFileParam(file_id:String, name:String, value:String):Boolean {
+ var item:FileItem = this.FindFileInFileIndex(file_id);
+ if (item != null) {
+ item.AddParam(name, value);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ private function RemoveFileParam(file_id:String, name:String):Boolean {
+ var item:FileItem = this.FindFileInFileIndex(file_id);
+ if (item != null) {
+ item.RemoveParam(name);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ private function SetUploadURL(url:String):void {
+ if (typeof(url) !== "undefined" && url !== "") {
+ this.uploadURL = url;
+ }
+ }
+
+ private function SetPostParams(post_object:Object):void {
+ if (typeof(post_object) !== "undefined" && post_object !== null) {
+ this.uploadPostObject = post_object;
+ }
+ }
+
+ private function SetFileTypes(types:String, description:String):void {
+ this.fileTypes = types;
+ this.fileTypesDescription = description;
+
+ this.LoadFileExensions(this.fileTypes);
+ }
+
+ // Sets the file size limit. Accepts size values with units: 100 b, 1KB, 23Mb, 4 Gb
+ // Parsing is not robust. "100 200 MB KB B GB" parses as "100 MB"
+ private function SetFileSizeLimit(size:String):void {
+ var value:Number = 0;
+ var unit:String = "kb";
+
+ // Trim the string
+ var trimPattern:RegExp = /^\s*|\s*$/;
+
+ size = size.toLowerCase();
+ size = size.replace(trimPattern, "");
+
+
+ // Get the value part
+ var values:Array = size.match(/^\d+/);
+ if (values !== null && values.length > 0) {
+ value = parseInt(values[0]);
+ }
+ if (isNaN(value) || value < 0) value = 0;
+
+ // Get the units part
+ var units:Array = size.match(/(b|kb|mb|gb)/);
+ if (units != null && units.length > 0) {
+ unit = units[0];
+ }
+
+ // Set the multiplier for converting the unit to bytes
+ var multiplier:Number = 1024;
+ if (unit === "b")
+ multiplier = 1;
+ else if (unit === "mb")
+ multiplier = 1048576;
+ else if (unit === "gb")
+ multiplier = 1073741824;
+
+ this.fileSizeLimit = value * multiplier;
+ }
+
+ private function SetFileUploadLimit(file_upload_limit:Number):void {
+ if (file_upload_limit < 0) file_upload_limit = 0;
+ this.fileUploadLimit = file_upload_limit;
+ }
+
+ private function SetFileQueueLimit(file_queue_limit:Number):void {
+ if (file_queue_limit < 0) file_queue_limit = 0;
+ this.fileQueueLimit = file_queue_limit;
+ }
+
+ private function SetFilePostName(file_post_name:String):void {
+ if (file_post_name != "") {
+ this.filePostName = file_post_name;
+ }
+ }
+
+ private function SetUseQueryString(use_query_string:Boolean):void {
+ this.useQueryString = use_query_string;
+ }
+
+ private function SetRequeueOnError(requeue_on_error:Boolean):void {
+ this.requeueOnError = requeue_on_error;
+ }
+
+ private function SetHTTPSuccess(http_status_codes:*):void {
+ this.httpSuccess = [];
+
+ if (typeof http_status_codes === "string") {
+ var status_code_strings:Array = http_status_codes.replace(" ", "").split(",");
+ for each (var http_status_string:String in status_code_strings)
+ {
+ try {
+ this.httpSuccess.push(Number(http_status_string));
+ } catch (ex:Object) {
+ // Ignore errors
+ this.Debug("Could not add HTTP Success code: " + http_status_string);
+ }
+ }
+ }
+ else if (typeof http_status_codes === "object" && typeof http_status_codes.length === "number") {
+ for each (var http_status:* in http_status_codes)
+ {
+ try {
+ this.Debug("adding: " + http_status);
+ this.httpSuccess.push(Number(http_status));
+ } catch (ex:Object) {
+ this.Debug("Could not add HTTP Success code: " + http_status);
+ }
+ }
+ }
+ }
+
+ private function SetAssumeSuccessTimeout(timeout_seconds:Number):void {
+ this.assumeSuccessTimeout = timeout_seconds < 0 ? 0 : timeout_seconds;
+ }
+
+ private function SetDebugEnabled(debug_enabled:Boolean):void {
+ this.debugEnabled = debug_enabled;
+ }
+
+ /* *************************************************************
+ Button Handling Functions
+ *************************************************************** */
+ private function SetButtonImageURL(button_image_url:String):void {
+ this.buttonImageURL = button_image_url;
+
+ try {
+ if (this.buttonImageURL !== null && this.buttonImageURL !== "") {
+ this.buttonLoader.load(new URLRequest(this.buttonImageURL));
+ }
+ } catch (ex:Object) {
+ }
+ }
+
+ private function ButtonImageLoaded(e:Event):void {
+ this.Debug("Button Image Loaded");
+ this.HandleStageResize(null);
+ }
+
+
+ private function ButtonClickHandler(e:MouseEvent):void {
+ if (!this.buttonStateDisabled) {
+ if (this.buttonAction === this.BUTTON_ACTION_SELECT_FILE) {
+ this.SelectFile();
+ }
+ else if (this.buttonAction === this.BUTTON_ACTION_START_UPLOAD) {
+ this.StartUpload();
+ }
+ else if (this.buttonAction === this.BUTTON_ACTION_NONE) {
+ ExternalCall.Simple(this.mouseClick_Callback);
+ }
+ else {
+ this.SelectFiles();
+ }
+ } else {
+ ExternalCall.Simple(this.mouseClick_Callback);
+ }
+ }
+
+ private function UpdateButtonState():void {
+ var xOffset:Number = 0;
+ var yOffset:Number = 0;
+
+ this.buttonLoader.x = xOffset;
+ this.buttonLoader.y = yOffset;
+
+ if (this.buttonStateDisabled) {
+ this.buttonLoader.y = (this.buttonLoader.height / 4) * -3 + yOffset;
+ }
+ else if (this.buttonStateMouseDown) {
+ this.buttonLoader.y = (this.buttonLoader.height / 4) * -2 + yOffset;
+ }
+ else if (this.buttonStateOver) {
+ this.buttonLoader.y = (this.buttonLoader.height / 4) * -1 + yOffset;
+ }
+ else {
+ this.buttonLoader.y = -yOffset;
+ }
+ };
+
+ private function SetButtonText(button_text:String):void {
+ this.buttonText = button_text;
+
+ this.SetButtonTextStyle(this.buttonTextStyle);
+ }
+
+ private function SetButtonTextStyle(button_text_style:String):void {
+ this.buttonTextStyle = button_text_style;
+
+ var style:StyleSheet = new StyleSheet();
+ style.parseCSS(this.buttonTextStyle);
+ this.buttonTextField.styleSheet = style;
+ this.buttonTextField.htmlText = this.buttonText;
+ }
+
+ private function SetButtonTextPadding(left:Number, top:Number):void {
+ this.buttonTextField.x = this.buttonTextLeftPadding = left;
+ this.buttonTextField.y = this.buttonTextTopPadding = top;
+ }
+
+ private function SetButtonDisabled(disabled:Boolean):void {
+ this.buttonStateDisabled = disabled;
+ this.UpdateButtonState();
+ }
+
+ private function SetButtonAction(button_action:Number):void {
+ this.buttonAction = button_action;
+ }
+
+ private function SetButtonCursor(button_cursor:Number):void {
+ this.buttonCursor = button_cursor;
+
+ this.buttonCursorSprite.useHandCursor = (this.buttonCursor === this.BUTTON_CURSOR_HAND);
+ }
+
+ /* *************************************************************
+ File processing and handling functions
+ *************************************************************** */
+
+ private function StartUpload(file_id:String = "", resizeSettings:Object = null):void {
+ // Only upload a file uploads are being processed.
+ if (this.current_file_item != null) {
+ this.Debug("StartUpload(): Upload already in progress. Not starting another upload.");
+ return;
+ }
+
+ this.Debug("StartUpload: " + (file_id ? "File ID: " + file_id : "First file in queue"));
+
+ // Check the upload limit
+ if (this.successful_uploads >= this.fileUploadLimit && this.fileUploadLimit != 0) {
+ this.Debug("Event: uploadError : Upload limit reached. No more files can be uploaded.");
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED, null, "The upload limit has been reached.");
+ this.current_file_item = null;
+ return;
+ }
+
+ // Get the next file to upload
+ if (!file_id) {
+ while (this.file_queue.length > 0 && this.current_file_item == null) {
+ this.current_file_item = FileItem(this.file_queue.shift());
+ if (typeof(this.current_file_item) == "undefined") {
+ this.current_file_item = null;
+ }
+ }
+ } else {
+ var file_index:Number = this.FindIndexInFileQueue(file_id);
+ if (file_index >= 0) {
+ // Set the file as the current upload and remove it from the queue
+ this.current_file_item = FileItem(this.file_queue[file_index]);
+ this.file_queue.splice([file_index], 1);
+ } else {
+ this.Debug("Event: uploadError : File ID not found in queue: " + file_id);
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_SPECIFIED_FILE_ID_NOT_FOUND, null, "File ID not found in the queue.");
+ }
+ }
+
+
+ if (this.current_file_item != null) {
+ // Trigger the uploadStart event which will call ReturnUploadStart to begin the actual upload
+ this.Debug("Event: uploadStart : File ID: " + this.current_file_item.id);
+
+ this.current_file_item.file_status = FileItem.FILE_STATUS_IN_PROGRESS;
+ if (resizeSettings != null) {
+ this.Debug("StartUpload(): Uploading Type: Resized Image.");
+ this.current_file_item.upload_type = FileItem.UPLOAD_TYPE_RESIZE;
+ this.PrepareResizedImage(resizeSettings);
+ } else {
+ this.Debug("StartUpload(): Upload Type: Normal.");
+ this.current_file_item.upload_type = FileItem.UPLOAD_TYPE_NORMAL;
+ ExternalCall.UploadStart(this.uploadStart_Callback, this.current_file_item.ToJavaScriptObject());
+ }
+ }
+ // Otherwise we've would have looped through all the FileItems. This means the queue is empty)
+ else {
+ this.Debug("StartUpload(): No files found in the queue.");
+ }
+ }
+
+ private function PrepareResizedImage(resizeSettings:Object):void {
+ try {
+ var resizer:ImageResizer = new ImageResizer(this.current_file_item, resizeSettings["width"], resizeSettings["height"], resizeSettings["encoding"], resizeSettings["quality"], resizeSettings["allowEnlarging"]);
+ resizer.addEventListener(ImageResizerEvent.COMPLETE, this.PrepareResizedImageCompleteHandler);
+ resizer.addEventListener(ErrorEvent.ERROR, this.PrepareResizedImageErrorHandler);
+
+ this.Debug("PrepareThumbnail(): Beginning image resizing.");
+ this.Debug("Settings: Width: " + resizeSettings["width"] + ", Height: " + resizeSettings["height"] + ", Encoding: " + (resizeSettings["encoding"] == this.ENCODER_PNG ? "PNG" : "JPEG") + ", Quality: " + resizeSettings["quality"] + ".");
+ ExternalCall.UploadResizeStart(this.uploadResizeStart_Callback, this.current_file_item.ToJavaScriptObject(), resizeSettings);
+ resizer.ResizeImage();
+
+ } catch (ex:Object) {
+ if (resizer != null) {
+ resizer.removeEventListener(ImageResizerEvent.COMPLETE, this.PrepareResizedImageCompleteHandler);
+ resizer.removeEventListener(ErrorEvent.ERROR, this.PrepareResizedImageErrorHandler);
+ }
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_RESIZE, this.current_file_item.ToJavaScriptObject(), "Error getting file for resize.");
+ }
+
+ }
+
+ private function PrepareResizedImageCompleteHandler(event:ImageResizerEvent):void {
+ event.target.removeEventListener(ImageResizerEvent.COMPLETE, this.PrepareResizedImageCompleteHandler);
+ event.target.removeEventListener(ErrorEvent.ERROR, this.PrepareResizedImageErrorHandler);
+ this.Debug("PrepareResizedImageCompleteHandler(): Finished resizing. Initializing MultipartURLLoader.");
+
+ if (this.current_file_item != null) {
+ var extension:String = event.encoding == this.ENCODER_PNG ? ".png" : ".jpg";
+ this.current_file_item.resized_uploader = new MultipartURLLoader(event.data, this.current_file_item.file_reference.name + extension);
+ ExternalCall.UploadStart(this.uploadStart_Callback, this.current_file_item.ToJavaScriptObject());
+ }
+ }
+ private function PrepareResizedImageErrorHandler(event:ErrorEvent):void {
+ event.target.removeEventListener(ImageResizerEvent.COMPLETE, this.PrepareResizedImageCompleteHandler);
+ event.target.removeEventListener(ErrorEvent.ERROR, this.PrepareResizedImageErrorHandler);
+
+ this.Debug("PrepareResizedImageErrorHandler(): Error resizing image: " + event.text);
+
+ if (this.current_file_item.file_status != FileItem.FILE_STATUS_ERROR) {
+ this.upload_errors++;
+ this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
+
+ this.Debug("Event: uploadError : Resize Error : File ID: " + this.current_file_item.id + ". Error: " + event.text);
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_RESIZE, this.current_file_item.ToJavaScriptObject(), "Error generating resized image. " + event.text);
+ }
+
+ this.UploadComplete(true);
+ }
+
+ // This starts the upload when the user returns TRUE from the uploadStart event. Rather than just have the value returned from
+ // the function we do a return function call so we can use the setTimeout work-around for Flash/JS circular calls.
+ private function ReturnUploadStart(start_upload:Boolean):void {
+ if (this.current_file_item == null) {
+ this.Debug("ReturnUploadStart called but no file was prepped for uploading. The file may have been cancelled or stopped.");
+ return;
+ }
+
+ var js_object:Object;
+
+ if (start_upload) {
+ try {
+ // Set the event handlers
+ this.addEventListeners(this.current_file_item);
+
+ // Get the request (post values, etc)
+ var request:URLRequest = this.BuildRequest();
+
+ if (this.uploadURL.length == 0) {
+ this.Debug("Event: uploadError : IO Error : File ID: " + this.current_file_item.id + ". Upload URL string is empty.");
+
+ // Remove the event handlers
+ this.removeEventListeners(this.current_file_item);
+
+ this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
+ this.file_queue.unshift(this.current_file_item);
+ js_object = this.current_file_item.ToJavaScriptObject();
+ this.current_file_item = null;
+
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_MISSING_UPLOAD_URL, js_object, "Upload URL string is empty.");
+ } else {
+ this.current_file_item.file_status = FileItem.FILE_STATUS_IN_PROGRESS;
+
+ if (this.current_file_item.upload_type === FileItem.UPLOAD_TYPE_NORMAL) {
+ this.Debug("ReturnUploadStart(): File accepted by startUpload event and readied for standard upload. Starting upload to " + request.url + " for File ID: " + this.current_file_item.id);
+ this.current_file_item.file_reference.upload(request, this.filePostName, false);
+ } else {
+ this.Debug("ReturnUploadStart(): File accepted by startUpload event and readied for resized upload. Starting upload to " + request.url + " for File ID: " + this.current_file_item.id);
+ this.current_file_item.resized_uploader.upload(request, this.filePostName);
+ }
+ }
+ } catch (ex:Error) {
+ this.Debug("ReturnUploadStart: Exception occurred: " + message);
+
+ this.upload_errors++;
+ this.current_file_item.file_status = FileItem.FILE_STATUS_ERROR;
+
+ var message:String = ex.errorID + "\n" + ex.name + "\n" + ex.message + "\n" + ex.getStackTrace();
+ this.Debug("Event: uploadError(): Upload Failed. Exception occurred: " + message);
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_UPLOAD_FAILED, this.current_file_item.ToJavaScriptObject(), message);
+
+ this.UploadComplete(true);
+ }
+ } else {
+ // Remove the event handlers
+ this.removeEventListeners(this.current_file_item);
+
+ // Re-queue the FileItem
+ this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
+ if (this.current_file_item.resized_uploader != null) {
+ this.current_file_item.resized_uploader.dispose();
+ this.current_file_item.resized_uploader = null;
+ }
+ js_object = this.current_file_item.ToJavaScriptObject();
+ this.file_queue.unshift(this.current_file_item);
+ this.current_file_item = null;
+
+ this.Debug("Event: uploadError : Call to uploadStart returned false. Not uploading the file.");
+ ExternalCall.UploadError(this.uploadError_Callback, this.ERROR_CODE_FILE_VALIDATION_FAILED, js_object, "Call to uploadStart return false. Not uploading file.");
+ this.Debug("Event: uploadComplete : Call to uploadStart returned false. Not uploading the file.");
+ ExternalCall.UploadComplete(this.uploadComplete_Callback, js_object);
+ }
+ }
+
+ // Completes the file upload by deleting it's reference, advancing the pointer.
+ // Once this event fires a new upload can be started.
+ private function UploadComplete(eligible_for_requeue:Boolean):void {
+ var jsFileObj:Object = this.current_file_item.ToJavaScriptObject();
+
+ this.removeEventListeners(this.current_file_item);
+ if (this.current_file_item.resized_uploader != null) {
+ this.current_file_item.resized_uploader.dispose();
+ this.current_file_item.resized_uploader = null;
+ }
+
+ if (!eligible_for_requeue || this.requeueOnError == false) {
+ //this.current_file_item.file_reference = null;
+ this.queued_uploads--;
+ } else if (this.requeueOnError == true) {
+ this.current_file_item.file_status = FileItem.FILE_STATUS_QUEUED;
+ this.file_queue.unshift(this.current_file_item);
+ }
+
+ this.current_file_item = null;
+
+ this.Debug("Event: uploadComplete : Upload cycle complete.");
+ ExternalCall.UploadComplete(this.uploadComplete_Callback, jsFileObj);
+ }
+
+
+ /* *************************************************************
+ Utility Functions
+ *************************************************************** */
+
+
+ // Check the size of the file against the allowed file size. If it is less the return TRUE. If it is too large return FALSE
+ private function CheckFileSize(file_item:FileItem):Number {
+ if (file_item.file_reference.size == 0) {
+ return this.SIZE_ZERO_BYTE;
+ } else if (this.fileSizeLimit != 0 && file_item.file_reference.size > this.fileSizeLimit) {
+ return this.SIZE_TOO_BIG;
+ } else {
+ return this.SIZE_OK;
+ }
+ }
+
+ private function CheckFileType(file_item:FileItem):Boolean {
+ // If no extensions are defined then a *.* was passed and the check is unnecessary
+ if (this.valid_file_extensions.length == 0) {
+ return true;
+ }
+
+ var fileRef:FileReference = file_item.file_reference;
+ var last_dot_index:Number = fileRef.name.lastIndexOf(".");
+ var extension:String = "";
+ if (last_dot_index >= 0) {
+ extension = fileRef.name.substr(last_dot_index + 1).toLowerCase();
+ }
+
+ var is_valid_filetype:Boolean = false;
+ for (var i:Number=0; i < this.valid_file_extensions.length; i++) {
+ if (String(this.valid_file_extensions[i]) == extension) {
+ is_valid_filetype = true;
+ break;
+ }
+ }
+
+ return is_valid_filetype;
+ }
+
+ private function BuildRequest():URLRequest {
+ // Create the request object
+ var request:URLRequest = new URLRequest();
+ request.method = URLRequestMethod.POST;
+
+ var file_post:Object = this.current_file_item.GetPostObject();
+
+ if (this.useQueryString) {
+ var pairs:Array = new Array();
+ for (key in this.uploadPostObject) {
+ this.Debug("Global URL Item: " + key + "=" + this.uploadPostObject[key]);
+ if (this.uploadPostObject.hasOwnProperty(key)) {
+ pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(this.uploadPostObject[key]));
+ }
+ }
+
+ for (key in file_post) {
+ this.Debug("File Post Item: " + key + "=" + file_post[key]);
+ if (file_post.hasOwnProperty(key)) {
+ pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(file_post[key]));
+ }
+ }
+
+ request.url = this.uploadURL + (this.uploadURL.indexOf("?") > -1 ? "&" : "?") + pairs.join("&");
+
+ } else {
+ var key:String;
+ var post:URLVariables = new URLVariables();
+ for (key in this.uploadPostObject) {
+ this.Debug("Global Post Item: " + key + "=" + this.uploadPostObject[key]);
+ if (this.uploadPostObject.hasOwnProperty(key)) {
+ post[key] = this.uploadPostObject[key];
+ }
+ }
+
+ for (key in file_post) {
+ this.Debug("File Post Item: " + key + "=" + file_post[key]);
+ if (file_post.hasOwnProperty(key)) {
+ post[key] = file_post[key];
+ }
+ }
+
+ request.url = this.uploadURL;
+ request.data = post;
+ }
+
+ return request;
+ }
+
+ private function Debug(msg:String):void {
+ try {
+ if (this.debugEnabled) {
+ var lines:Array = msg.split("\n");
+ for (var i:Number=0; i < lines.length; i++) {
+ lines[i] = "SWF DEBUG: " + lines[i];
+ }
+ ExternalCall.Debug(this.debug_Callback, lines.join("\n"));
+ }
+ } catch (ex:Error) {
+ // pretend nothing happened
+ trace(ex);
+ }
+ }
+
+ private function PrintDebugInfo():void {
+ var debug_info:String = "\n----- SWF DEBUG OUTPUT ----\n";
+ debug_info += "Version: " + this.build_number + "\n";
+ debug_info += "movieName: " + this.movieName + "\n";
+ debug_info += "Upload URL: " + this.uploadURL + "\n";
+ debug_info += "File Types String: " + this.fileTypes + "\n";
+ debug_info += "Parsed File Types: " + this.valid_file_extensions.toString() + "\n";
+ debug_info += "HTTP Success: " + this.httpSuccess.join(", ") + "\n";
+ debug_info += "File Types Description: " + this.fileTypesDescription + "\n";
+ debug_info += "File Size Limit: " + this.fileSizeLimit + " bytes\n";
+ debug_info += "File Upload Limit: " + this.fileUploadLimit + "\n";
+ debug_info += "File Queue Limit: " + this.fileQueueLimit + "\n";
+ debug_info += "Post Params:\n";
+ for (var key:String in this.uploadPostObject) {
+ if (this.uploadPostObject.hasOwnProperty(key)) {
+ debug_info += " " + key + "=" + this.uploadPostObject[key] + "\n";
+ }
+ }
+ debug_info += "----- END SWF DEBUG OUTPUT ----\n";
+
+ this.Debug(debug_info);
+ }
+
+ private function FindIndexInFileQueue(file_id:String):Number {
+ for (var i:Number = 0; i < this.file_queue.length; i++) {
+ var item:FileItem = this.file_queue[i];
+ if (item != null && item.id == file_id) return i;
+ }
+
+ return -1;
+ }
+
+ private function FindFileInFileIndex(file_id:String):FileItem {
+ for (var i:Number = 0; i < this.file_index.length; i++) {
+ var item:FileItem = this.file_index[i];
+ if (item != null && item.id == file_id) return item;
+ }
+
+ return null;
+ }
+
+
+ // Parse the file extensions in to an array so we can validate them agains
+ // the files selected later.
+ private function LoadFileExensions(filetypes:String):void {
+ var extensions:Array = filetypes.split(";");
+ this.valid_file_extensions = new Array();
+
+ for (var i:Number=0; i < extensions.length; i++) {
+ var extension:String = String(extensions[i]);
+ var dot_index:Number = extension.lastIndexOf(".");
+
+ if (dot_index >= 0) {
+ extension = extension.substr(dot_index + 1).toLowerCase();
+ } else {
+ extension = extension.toLowerCase();
+ }
+
+ // If one of the extensions is * then we allow all files
+ if (extension == "*") {
+ this.valid_file_extensions = new Array();
+ break;
+ }
+
+ this.valid_file_extensions.push(extension);
+ }
+ }
+
+ private function loadPostParams(param_string:String):void {
+ var post_object:Object = {};
+
+ if (param_string != null) {
+ var name_value_pairs:Array = param_string.split("&");
+
+ for (var i:Number = 0; i < name_value_pairs.length; i++) {
+ var name_value:String = String(name_value_pairs[i]);
+ var index_of_equals:Number = name_value.indexOf("=");
+ if (index_of_equals > 0) {
+ post_object[decodeURIComponent(name_value.substring(0, index_of_equals))] = decodeURIComponent(name_value.substr(index_of_equals + 1));
+ }
+ }
+ }
+ this.uploadPostObject = post_object;
+ }
+
+ private function addEventListeners(fileItem:FileItem):void {
+ var item:EventDispatcher = fileItem.GetUploader();
+ if (item != null) {
+ item.addEventListener(Event.OPEN, this.Open_Handler);
+ item.addEventListener(ProgressEvent.PROGRESS, this.FileProgress_Handler);
+ item.addEventListener(IOErrorEvent.IO_ERROR, this.IOError_Handler);
+ item.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.SecurityError_Handler);
+ item.addEventListener(HTTPStatusEvent.HTTP_STATUS, this.HTTPError_Handler);
+ item.addEventListener(Event.COMPLETE, this.Complete_Handler);
+ item.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, this.ServerData_Handler);
+ }
+ }
+
+ private function removeEventListeners(fileItem:FileItem):void {
+ var item:EventDispatcher = fileItem.GetUploader();
+ if (item != null) {
+ item.removeEventListener(Event.OPEN, this.Open_Handler);
+ item.removeEventListener(ProgressEvent.PROGRESS, this.FileProgress_Handler);
+ item.removeEventListener(IOErrorEvent.IO_ERROR, this.IOError_Handler);
+ item.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.SecurityError_Handler);
+ item.removeEventListener(HTTPStatusEvent.HTTP_STATUS, this.HTTPError_Handler);
+ item.removeEventListener(Event.COMPLETE, this.Complete_Handler);
+ item.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA, this.ServerData_Handler);
+ }
+ }
+
+ }
+}
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/deploy.bat b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/deploy.bat
new file mode 100644
index 0000000..08fd171
--- /dev/null
+++ b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/deploy.bat
@@ -0,0 +1,4 @@
+@echo off
+copy swfupload.js ..\..\samples\demos\swfupload
+copy swfupload.swf ..\..\samples\demos\swfupload
+copy ..\plugins\*.js ..\..\samples\demos\swfupload
\ No newline at end of file
diff --git a/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/jpegencoder.swc b/media_tree/static/media_tree/lib/swfupload/swfupload_fp10/jpegencoder.swc
new file mode 100644
index 0000000000000000000000000000000000000000..b527fddd429ee3131c49454078488599926f7817
GIT binary patch
literal 167837
zcmZsgV{|6Z6R4AHY}>YNY;4J
zKd(5?l&*Nt;F*i`H!j;nw4Z2$Po{Lh7s{6h+K3DW^?|g0=c57{O6DxNJjbKrwDY#2
z5m#s0f;scRMjUg8=7(G0r6#L=21z&~4={@L6TL}*Dhf)g#yZ-6a&6Pt{?JOpAPXf#
zK@*bs?JVP{MRi3LTs1m3UymOB7*3)P(9!RWbz^N5!B0`V$&KQU%2-7*aoN>`%WX(bqW=Nk~hOTsmpSeDjonifzi`aGrc
z1sONTDbr)V$%+7?tS5t0dY<0T^sW6tQQ16mHy!_laF=
z9k?c2x5JoSyw5f*S)ElV9Tg&qH3l}Q9e#<
zZuV%%&)*V#8*JE%iAWpDlxmn}deJuk#A9u{LQAl7_3Yon1-nBZI+bBVOHDOeGAw(w$0*}*tgf!9scEjMurNap3#aF_By%`MCQ4QY
z7d&EMIK(RAJXH1H`X{Zfrn0QOu;P5gorPpYv@9+czy|hK!ViYZUW;9-U5Nut7LAb}
zy$PJOg*j2mRqZiEj|^9$n5m6=#bk+fcvyVoc?Zy-5}@>$VX;lTe6CtdYUFBs9vY2S
zJL>bFtV!ypf$qTtIfA(f!zirVh4($QTh5`%K5
z7EvRuH=SGTL`8?aRaLBF9gOgvm;~utbL=m)
z5cWB1XLS6C1M26OTN6B)GNzk1L$tWoZm&MGzS!pJZgIA|9*&=5DJ&F!EVGiUK9E~d
zZ(Q3j6YtPFgX{j7*k_s3SAE7?{eHLaIX|+OfBs~3cTy+6xe@1o4*{h_c!hD^av~KJ
zHsA4^fpGoxGL*0H%PU7%j2%`=9otn*uWr&*Bw5d&lCB(~smj#x)-Kk;zw-HhxqBpX
zJ2kbH$?#~KL*TjlF&lUsy6x+Gl7BC9%_;D3^O`R{jlk#Wds25V5-Y&kfF)
zm51+nAKMe~1-Rdj`H$ohcpl%2$ny$3RR28w`7ui%Akg^gy>oN~HtKTEhY-Zhq3?y*
z{dJZ0ohxt>;79_`0f20MqqwO0kXQc@in$PW(`a;P<*ESl@>A(ic3kgYqVD
z{krWXBHwjW{2a`GcUE`}F&M1x_Wfx8eGEbPFz@8=_xa>>O!TlD*|)?0F&Zke^L6U>
zMRM@bR3qm5wTmHuz5cPKFM#TC+2-cW>%8|d@lE$Ocir>heA0x`eIs)+Ch&SU*rMn2
zUMkG+ahItN-Suf)^F{j*?dN-O-T(cHu=CM!^34DBJR_F-{ZOL^<9nCO|GpFG_c+z_
zYIE{T;CJ@fC+_z-lZ(LG^SxP0GQ)rSux6g?Ui>wW(9?kTA;0ssak-0-`$e$Pm+SLS
zd84o9b0yYW;H|@ayAJQ;J+=EQ)Ij~2{o`>sFkFEa5srdHzSDE}5CPw7M?Tk!FeuH!
z$_b?cXMo!69|kalqFEQ>yJJmlo5%Un(-@u)AL<7Yp*xZzMsr~%?V)LArf`NSp^g0x
z0+$XLa_0?FK=%#Iq$Lk`W815R^L<~h7e1`P*}>5fP1;Z}0nwZI90WTaRE)U@(HaO*y@nonEH9)FNIxUy8<8DTjLw#8*F{zV@6=?=ylPoX(rs@M}AWo))~1
z0oU5+@rvda0!W`v7=QmhK6Tjd^LLyNW*>_YDMd#bzEN47Wbr`%De6YHAYdxGtU
zEx$jS_eZ%OJNdar?M~+1ud$6E)jOT5Uf&-RGyHcP
z6cpPIZx(#bP-*)f%%+H+Y>eW7$2w%(d*K92l+E=~z@KSZRwUXxpVjt>U>
z8l9fHdGz=^K9S09DFj|0C8d0WmX0x=8$7qZ^*uX;D>8_SOE^^ON|I8XZGDX6)`AsN
zb;D?y+DkIqqSveYRjw@d7DK4yPup7+fkY?`Cs(%uG#1d5$m7
z<}&Z!RTM5nXO~gr7znN}pf;SNqw|jTvIYP91?-Hfp9DKM$u0j7x$;{|87`b4B&Cm;W@bcIHnkEAm9S2Ava0
zDRsX9Sl8=M|&`t_81+0yimE#XLaK`T2-zeHBDCob=nc5@q&unEP7U*)b_=
z=!~0VU;xS*N{{O!(?4)kNRTS5Ljn@8LXUz{X6zRaMFMzWxd#w*Z6gN}F@6`D=~aUbl~OFZr|=|a{tbhUR{?awc@5p27R&-bdtoAI|iZO(72
zC|b5#9v7G2Tli}q`>O7>3D)0kmRYoOH{TYQOI!FG9@nbOTliZZU#pH=zP!(+wHa(a
zhn7=Yz5wSm+WNNqtKMGs`A0k%2pj~K{OjJ8uRm`8=siQ8ZD;30@IG+rehPt2VDsbm
zefkkaX0DZQ`)m4}&Q9C-*{X`|EtqE)@&pG=B8JO4BM8O!!=M+wG0`y?)ILffzK`GsNhGEtfMW}{-l~D`c7g^G_q^J>UyYW?K(uaFQ
zx}I6!h;`_yIyVLG42KlzCPbT@*A5}CxKtI%_$GOYJEs;XT(QL07NVG{N^Gwp0%U0&
z2hOv-EkoYneKFcff>Z=_9V{pBZzaP1d`Lv2un1S~DmTMO9uB=U=;D6m($XaQm$@m>
z&d2_j=MzxX+=B{u5cyb|-6(KX!8tLm=1z;<+*V4-B=
zrwLXV*uy{28){Y`=lCZ#5OO`-V3<$@g67J=B1{A5+K!w}feK}PaO}p!S=)2Lc4S2q
zD+*RbODrvgG>8!h6fa0BxVeov4@ccHHmexgv^dh@;YEMS90m2|!}2-t;IdVh&0o`m
zl(r%xAEcEbfjsd@swV589p-TX#o$QhRf=qAf5T>hL|`PZY{SaSHpQ1oFrD6u&H>eS
z%{7i{$cZ7UjY7&{|u4!LFxxdL?h*b@ejmwdDQoAZsKttl`MU
zk?Dj{e5Hf)T&Tr{MulDv<~1u)fdKq;4T^LkET;8(=O){Yyq*c8=qSp90%9bzw^6*y
zfZbyk#0nCnVlhQ|=s~zpAy{x>8aN-F_+WbT*x!?1_>_B?5bWoS)+FQ{YsGW#Ma|Wn
zJ;~VE4YW1>;kQMM)&FLj%x!S%*Qcu?Sb}F!69d{x`V6=y#ORDGNgSh3xuUvh`y@7M
z1C+sPBN9o~QFztJ^Q8?*tm_MK{b4QwZ2bg4t|J&5
zZxTGtmWYEWe2Giy4lxm`VCy
zWI6BzNDtIm(}18$#e=yNlf7cmzzp|YLXSm18Tb1j*<|(?8nv+kTa!k0B~e@g@6>~G
z{Ff-;ctulXOH)#Y?G1?28aqjuE0ZgXh6q90472&*naZp@;k;I{+6TiuaO;ZPfp|vF
z%^Mm>Len_F$)7wiigmHc$aGpQYck1Q1=9eyJDn3cGWEy!VrJ>Qy9Wx(`4~VXfer1jveCatoo%5|I6^QYEmpMp%CImA(I-IW!atWMU3V1A
z7LLJ_60}|IZexY{^595u|H?S`Eyv&c%oA);ol$H2I_ac|)=~u9GAzW#BEIYka@Stm
zXe9GWL#3?Aw0UTda@l|h%~0`Q)uF`die5&p2?TB>RjO(4$BAt>4s16GqZJTj#qeT;%bwUZWbycX?>sArfNubn?-nFo?T(J
zbP7s!^2lmfVuiz7iExW5GEy=eHVY67Yd>&j=T0%)Od=Tv!)A_*sjC_{;F7sH?R(aZ
zuRBl7Ve!@*;ER&fvZiUFS#L;?;><_9
zeFylP>0nlkZe6Ql_gx`&U*;W5imlE+2$?2jW-!oO2hjZ}DY<
ztdTjmpuHlw0F;?5JrqeofG-w};#y)vgU{fM$$UCG6+sCCnQ_UjZw%vfCFLsB%1!#bl^~&wZ_-hXT4pw7
ztuXs~(~BK6Y1pC$sfH@UA1y8BXFDybL5B*E@@p|Ah#Lx2ihs|QNFq9Jg*UT+u+@ya
zkwG1>8;MYzTs5k4MunH-lBci>SJ?!~y%0D4FS$@`gA9l>h_3tqCnW(L?v28!Z~Gk<
zs9Kd^_b2$T44TlH0Z&b6IM8Iu3@77_6d01o^5~y#Do;G6`DDAG676pH^0X#Rq!td5
zr@Vh1B@Nlg7d9!tJVc~fbV>O0Bc*D6(}r@6UMplNeTO!2#-QW5nl%*HOz_>evwVs6
z0p^&jN=yrA>9n!A>l%MzkcX0XQAEoUbHn4Afe;O~DY%qFyYYe#LU&R4iY-+&RR*vW
zFi4U$11zCvYEuubXQQIOn&C1SJ;&0MaPX-`2!nKeW6dm-_v$;yE>d
zxxHZfZoKs|5s+*^WmxhunG|c{0EHETHR@4+Gy}De^gtp|Tb`qhPQVX)Uq+z(IP=3W
z8(r^bGYRiUL6}rOr6b#H_`O_9;!Jr^KVf#|ya;`M%Q22AQ1_xTZvs`NxOplrUiQ+5T1(fz3NKb$y;QhQ?amHI!VJfPB6{h@
zBuJ$0*!+v)*vtk_&Oaty6${r)RE31u1CqY8S8(Q#tZKoZD4gP;A!ydRsjWbzMyH!8BWxRIj9
z+P#>`)@(!uzECQK0!*p
z`ENK|pXzG=PLLr_KOBd&RMrm6{x*HcB~l$>aXuMT;yB%da#M0~vD-K(rxr+ES%g$c
zcx=x5J?g8LP)F%D{Av=;N(-`vh|G!lcI;pXjkzVti9>)M)B>PRv1}B8yosDflwh$)
zSaE}VD#^xGjX42__Sv5%I0FNnx8!1Z^8WBhk%gX0TUF`
zywn2N-b)?OLHZ4y(
zA<0Qh%pcAqiI`-c^$e+TFr=T^QFW)K6hmT}CC0PCdSVsp$OKtYSTX$xNh6J71I(dI
z9pK0(Fl%#w2}EMBWTg1gH%#j6&aHGBg$+;m>#$!WQ$FBj=J6zK;2z7hn+6j%=otcF0oU}
z+Dm6uC|$A0Qf)@)5cA|54M+P@7{lcq?D^{h`uMfB5tDZ%wxL
z53vknB4U%m7}{LzKm?O%KsCA$n-Mi7g_XlPw29*mLkv>^spP?1e%8*86{{ul~Qxf3(1=T7_wP<`uZsYv9P|aPNoZh3xCSQbI_O!F&
zu$08g1|<-anE*!d!A=NLTwcL8$1PRz!yznvO{(b^@H1wg-A+FtlF0;x7s4+vcxa}`
z@2j!Dl?iRykbEnkW4R82qzeGNqdezSp3`!_XMa-qx40^F%)eqm1H$uUjf{>J!V53K
z9WFw~{HerFWJii%J8#P^AqK9-MW^1T=ne)`BAn{5kPt?uNl-xZy>ye9(#NA0xLp0d
zbk|Q3L?YQ{#8HIqvz9R034JtCvrqYGB&u@r%=g%+h=m4KLCgFUsZm)r)5rU+@taKR
zPsI(9w*_eM%cyLp{W@dP>7g-TO`Vj!-qYlASwp+T}(|4(lOV{DpL@
z)$^s6L0HJIS`zy%LP&`dEqOK+6f2}G2jI@+evg@b8F5L$UK())_%gqYKA&tQQ__$^
zWiL-EwWDGyRAhzCQ3iYrGzr%!#uzuVG*Yv;9U9WNJChSIQe}-&?MYNN2x1836%8ds
z{Tk#f!)U9@t%@3drDCzv<*#Ovb^>`sQ6NcsIDuM|kP0*v8rKDn{
z{tF|&u?RO?QYUpm)=)`Nf)#}4*65rbv&sT%m)p$I)atzw?mnklEmB_EfT0j
zzSTVH9X@kdr$h}<2vb6+b0~2!Lod^5WvQjWCoYeM}K0|k_psT&3aDM@_07BIUT6P
zuAVTdl=y%=ZON_m;Ve|){-T@VD-O{{0G2aTeRIIXyrulP6NH8s@R3j@_(TGdc!$_#
zj=SbUJ`J$CBfu8~&X&25%^8fh5ey5K=h9iOM{=V*EXOkKuO}pi132lvta&+fBN5wB
z$E-^^v@;{h@-S<@a90>)b*f-TFD~|rbe3k0u~LkPLktkaCE^(j9S?xIgR#lmO}L(@
zZgT%)eiPP$)eOzl6Z>zH*D5%Bwkcj%Oq>%AM87GPS+pWJT+AOO4W6ypBM2iB=j%to
zYsj_P!cai(1~iIu(BwEInq(3HCgnO>3Bh6YT#D&rsjK3qh_7`pWjE
z`n3(w-4GD;lrtLi
zo1Lo(F9cB)I!atL3JSS~wHb_X4N9n06Hg`B8nd9``wW<(YO^+RKBHNX#38}m2W}f^
zw5A^$;kg&*-%eicDuay(-ikhXXle(AaX?Bjpe1Yv9-kwr}
zVl##rAlY01D?}n=W7&dDAFsxC=7_m}O*&yXhg==RaYiK!z`+~z+>Dnb>dH%(@(A=8
z->M**B!|p>Iiu7Z$Uy}uz+{Z(T=NtRjn}7`q0N@>|1Cvj?2azLaNdN^khS65(B=UM
z-=%BvjN&H`{$hTii?U}7U}-BZij1O>3#hTO0)yPY;G%k{L$nL*6=b0rJkeCbWiU(;
z!WVUi?Km}{4It#^`$cCUkpRFLd{p68LfBg?(?fu?2`M+NeQkA8P7uIXi`gLZYeNf*
zjdKq6xhFlhkpxrsq-K2c=PSU0S7Wt90ZSqQHs#He0Zl68xoqe-fUGWnP8x1WV@4jn
zR1jsz4TBBvPTyL
z_a@IGq=1Rot*$iS{ykjT>)-_db>bl`iD$**s5EpxxfT258qSpb2StIYU9986RQ^@1Bb1LuDiFX(|Q%+Y`Ba>E5rKxqdOkqPty
zsvrk+I0$zGoDpt(1KbXkmkHEf80Sr_03K2JFDu22?CSCOY8$+jx~czRP^Cx#k*w@D
z0W+_`4dqu|(0n|oDrNbrkQ
zdpwJ}O5>*LTUC@TSLpS>GF2}n6q(>KGU+8C(od_Hoq+I^`fzp1wvVL_fw(P99fbjw
zWRWhE#l)F3ckLCZ5WTkY5PbW&R0I6@2iq{_GfT4
zL!~%{@SQ;SHY_;Bqcwr$3W-*ChWBlXYSjX`mm)rGHVkRT<)J-%IlCpQs{+lsBdOl>UCFlhX9Mh1bh#2GAgolYIY0fy
zxZO<|FAPfkc`4pD2=S!+C4&Y~qMfnZEP7Ka}-OF(%Ux`Lg#96bcFNEmcvEjQQeLtSx&&*cEvJ
zn=2soY4F9UpjEE2D&;oh&(dQRWiDIDMUt*8F9imUt1IpJObn5aseRl$vRoXASHz8~
zqbAJ;_@7`NN`MF$Lw6EDyfs2b5wG2&@T@W~p0OnpMJCh(AiA;)eG-Q;+BJozbJDbF
z*_s;Ck!j>1Rjz{gC>7WVun&Xi4B1HKBkk_S+RC6_9Ez|Bf)P^`z@Y9`*Qc5G+ryy%
zb>umqaSA?4`EgxKjoXv~#DtQu9OH`05T_L-jg3DR_?Jrbr5rzpczhxx9U#tGZl3S$
zAq2({0Yx#o7fkF;CRr&TZ^Z!P)R=1c@lLPtdl(Y#?u}mPg;^M!VHgs|3DYo5#J9~L
z3!q)gU~zdTqO+1C5PR_!6TD{>dXJou&41&=FX~aotqzmQIp(9fKIQgG^ijSfb=0u{
zVYu&=GsJzd}osAlFC(nq_S{yZt=1?kr%q1=QQ
zl=qP8im8DheG*&OpPDnQePFJAE3#WWFGNX>PwdBTH6ZiH^=SSR`!dxbjr>M7BzZ1`
z`#vv^<&NZ0w_>4cf6s-EiY~fa8h0%#W1eG9AvxQ}=D|-uk;aZtApXG&l2kL7_mm^mSWEnms3x1=A!cq@;nmXvUn}Vuo<8Z{
zVbh#W5$ppVCI?Te!Va?zYxie>Vu6rh(SSE&seU7hZV~lhd!yiaA9v!Oq2OXzJg95NT
z4?64}04HJhPHr@iH*%VyE6HllVpfYT$fX)x$r(G1mlp2!&xik*$iB7iX3)zQp~u$d
z>91oA4EQBc(Bet+X;cF-PX1B<*N8qcdhh7LK}3X6BoUhM>-EaVas=YaFLp?CI7eHRnJ;{Q|@^5<}>?`fqkR7sOcj+dsHSKMNWmQG*JDQ;eK!>4y_ULX5Dj&Ol53
zhA!+B_v^ljbzb%6a3abf4C0~5vv_@&i}ol>v@Hu7%TmzD39g8XMG5cGw=;~UwMJD196?{ArycgR<>LZv3|
zUT}xN7Q=0EB2)((I7MKB1S-7CA=#)u&rVB(g;O~jJQ|08+6{s1Qmj=bXFko=m
zvSsJ<_sS7)+PD49K2ws)xTCT>OOUGn>%9WqrE_`^P2cf>nAIeVzgCROeyF~>Sd3J;6i7#eyiHq@Q^tCrIh$kdK?WEa!B)?P>fIWj7f8>wnXdtiKXcXEOXP
zxNgXwW=ysb&dtC!rln~Aw~NlPrTcGSitvaZv|%m=A7&%mtj9sG;LCF1%iuF|Fg8C^T6f(XU;KS9km!^@gEn$
z_R^ai;sKAg2x`bxn$5H>vZzGgJ>f1u9D)5_{xH@4*zqkkr%I}t
z(p+iLK3TH!9Ji2B8aa}du+_zbzmv38;hinAq;V5HrPlxYA+>WZm5HoMN9QrOD)fP%
z@C4r6Qux`+<_=aA?L|frA4UDz3|
zPg}(4j5LTDKdQKArQ1KBp7ENprEYUxV{{JZRd)3`IVJX%#njkID|`R)KPKbQHUPyVxYTJCg@A$CJ$1MhCC