Author: Crafty_Shadow
Date: 2010-02-04 09:28:51 +0100 (Thu, 04 Feb 2010)
New Revision: 27543
Added:
plugins/dmMediaUploadifyerPlugin/trunk/config/
plugins/dmMediaUploadifyerPlugin/trunk/config/config.php
plugins/dmMediaUploadifyerPlugin/trunk/lib/dmMediaUploadifyerConfig.class.php
plugins/dmMediaUploadifyerPlugin/trunk/modules/
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary/
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary/actions/
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary/actions/actions.class.php
plugins/dmMediaUploadifyerPlugin/trunk/web/js/dmAdminMediaUploadifyCtrl.js
plugins/dmMediaUploadifyerPlugin/trunk/web/js/sfWidgetFormDmUploadify.js
Removed:
plugins/dmMediaUploadifyerPlugin/trunk/web/css/default.css
plugins/dmMediaUploadifyerPlugin/trunk/web/js/dmMediaUploadifyerPlugin.js
Modified:
plugins/dmMediaUploadifyerPlugin/trunk/
plugins/dmMediaUploadifyerPlugin/trunk/lib/form/dmMediaUploadifyForm.class.php
plugins/dmMediaUploadifyerPlugin/trunk/lib/widget/sfWidgetFormDmUploadify.class.php
plugins/dmMediaUploadifyerPlugin/trunk/web/css/uploadify.css
Log:
[dmMediaUploadifyerPlugin] First working version :)
Property changes on: plugins/dmMediaUploadifyerPlugin/trunk
___________________________________________________________________
Added: tsvn:logtemplate
+ [dmMediaUploadifyerPlugin]
Property changes on: plugins/dmMediaUploadifyerPlugin/trunk/config
___________________________________________________________________
Added: tsvn:logtemplate
+ [dmMediaUploadifyerPlugin]
Added: plugins/dmMediaUploadifyerPlugin/trunk/config/config.php
===================================================================
--- plugins/dmMediaUploadifyerPlugin/trunk/config/config.php
(rev 0)
+++ plugins/dmMediaUploadifyerPlugin/trunk/config/config.php 2010-02-04
08:28:51 UTC (rev 27543)
@@ -0,0 +1,33 @@
+<?php
+/** @var dmAdminApplicationConfiguration */ $this;
+
+
+$this->dispatcher->connect('dm.media_library.control_menu',
array('dmMediaUploadifyerConfig', 'listenToMediaLibraryControlMenuEvent'));
+
+/**
+* Let's talk a bit about the next piece of code
+*
+* The reason we need it is because of a bug in Flash 9+
+* When Flash makes an http request, it doesn't send the active cookie when
using a browser other than IE;
+* This means that an authenticated user would be unable to use uploadify,
which would defeat the whole
+* purpose of having it in the admin panel ;) So we use jQuery.metadata and
allow for the session_id to
+* be set through POST params.
+*
+* This code needs to be excuted before the storage factory is loaded, ie
before context.factories_loaded event;
+* In symfony, there is no event preceeding that, which means we can't use
events in this case.
+* This leaves us with two possible sollutions:
+* 1) Write a custom storage class to execute the code before calling the
initialize() method of the parent
+* 2) Simply write the code in the configuration, ie here
+* The latter is easier on all levels :)
+*
+* This code poses no security risk (although de facto it opens the possibility
for session riding,
+* it uses non-standart param names and also uses the POST array, which makes
the attack quite harder;
+* esp given that the attacker would first have to get the contents of the
symfony cookie (actually,
+* of the cookie with the same name as the uploadify_session_name)) and creates
no overhead;
+*
+*/
+if (isset($_POST['uploadify_session_id']) && $_POST['uploadify_session_id'] &&
isset($_POST['uploadify_session_name']) && $_POST['uploadify_session_name'])
+{
+ session_name($_POST['uploadify_session_name']);
+ session_id($_POST['uploadify_session_id']);
+}
Added:
plugins/dmMediaUploadifyerPlugin/trunk/lib/dmMediaUploadifyerConfig.class.php
===================================================================
---
plugins/dmMediaUploadifyerPlugin/trunk/lib/dmMediaUploadifyerConfig.class.php
(rev 0)
+++
plugins/dmMediaUploadifyerPlugin/trunk/lib/dmMediaUploadifyerConfig.class.php
2010-02-04 08:28:51 UTC (rev 27543)
@@ -0,0 +1,20 @@
+<?php
+
+class dmMediaUploadifyerConfig
+{
+ public static function listenToMediaLibraryControlMenuEvent(sfEvent $event)
+ {
+ /** @var dmMediaLibraryControlMenu */
+ $media_library_menu = $event->getSubject();
+
+ $media_library_menu->addChild(
+ $media_library_menu->getI18n()->__('Add multiple files'),
+
$media_library_menu->getHelper()->link('dmMediaLibrary/newMultipleFile?folder_id='.$event['folder']->id)
+ ->set('.new_multiple_file.uploadify_dialog_me.s16.s16_file_add')
+ )->end();
+
+
dmContext::getInstance()->getResponse()->addJavascript('/dmMediaUploadifyerPlugin/js/dmAdminMediaUploadifyCtrl.js');
+ }
+
+}
+
Modified:
plugins/dmMediaUploadifyerPlugin/trunk/lib/form/dmMediaUploadifyForm.class.php
===================================================================
---
plugins/dmMediaUploadifyerPlugin/trunk/lib/form/dmMediaUploadifyForm.class.php
2010-02-04 08:05:28 UTC (rev 27542)
+++
plugins/dmMediaUploadifyerPlugin/trunk/lib/form/dmMediaUploadifyForm.class.php
2010-02-04 08:28:51 UTC (rev 27543)
@@ -9,5 +9,8 @@
*/
class dmMediaUploadifyForm extends PluginDmMediaForm
{
-
+ public function configure()
+ {
+ $this->widgetSchema['file'] = new
sfWidgetFormDmUploadify(array('add_sessionid' => true));
+ }
}
\ No newline at end of file
Modified:
plugins/dmMediaUploadifyerPlugin/trunk/lib/widget/sfWidgetFormDmUploadify.class.php
===================================================================
---
plugins/dmMediaUploadifyerPlugin/trunk/lib/widget/sfWidgetFormDmUploadify.class.php
2010-02-04 08:05:28 UTC (rev 27542)
+++
plugins/dmMediaUploadifyerPlugin/trunk/lib/widget/sfWidgetFormDmUploadify.class.php
2010-02-04 08:28:51 UTC (rev 27543)
@@ -18,8 +18,11 @@
* Available options:
*
* ** Options **
+ * * upload_route: The route of the action that will handle the upload
+ * * uploadify_css: The css file to be used to style the Uploadify markup
+ * * add_sessionid: Because of a bug in Flash, it does not send the
proper cookie when uploading a file;
+ * Use this option when you apply uploadify in a
secured environment
*
- * ** Attributes **
*
* @param array $options An array of options
* @param array $attributes An array of default HTML attributes
@@ -28,12 +31,16 @@
*/
protected function configure($options = array(), $attributes = array())
{
-
+ $this->addOption('upload_route', null); // will default to the form upload
action through jQuery traversing
+ $this->addOption('uploadify_css',
'/dmMediaUploadifyerPlugin/css/uploadify.css');
+
+ $this->addOption('add_sessionid', false);
}
/**
* We want this to gracefully degrade to a normal file field if JS is not
available
+ * Therefore, everything we will create here will be done through jQuery
*
* @param string $name The element name
* @param string $value The value selected in this widget
@@ -46,6 +53,43 @@
*/
public function render($name, $value = null, $attributes = array(), $errors
= array())
{
+ $class_addition = 'uploadify_file_field';
+ $attributes['class'] = isset($attributes['class']) ?
$attributes['class'].' '.$class_addition : $class_addition;
+
+ if ($this->getOption('add_sessionid'))
+ {
+ $attributes['data-session_id'] = "%s";
+ $attributes['data-session_name'] = "%s";
+ }
+
+ return sprintf(parent::render($name, $value, $attributes, $errors),
"'".session_id()."'", "'".session_name()."'");
}
+
+
+ /**
+ * Gets the stylesheet paths associated with the widget.
+ *
+ * @return array An array of stylesheet paths
+ */
+ public function getStylesheets()
+ {
+ return array($this->getOption('uploadify_css'));
+ }
+
+
+ /**
+ * Gets the JavaScript paths associated with the widget.
+ *
+ * @return array An array of JavaScript paths
+ */
+ public function getJavascripts()
+ {
+ return array(
+ '/dmMediaUploadifyerPlugin/js/swfobject.js',
+ '/dmMediaUploadifyerPlugin/js/jquery.uploadify.v2.1.0.min.js',
+ '/dmMediaUploadifyerPlugin/js/sfWidgetFormDmUploadify.js',
+ $this->getOption('add_sessionid') ?
'/dm/core/lib/metadata/jquery.metadata.min.js' : null
+ );
+ }
}
\ No newline at end of file
Property changes on: plugins/dmMediaUploadifyerPlugin/trunk/modules
___________________________________________________________________
Added: tsvn:logtemplate
+ [dmMediaUploadifyerPlugin]
Property changes on:
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary
___________________________________________________________________
Added: tsvn:logtemplate
+ [dmMediaUploadifyerPlugin]
Property changes on:
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary/actions
___________________________________________________________________
Added: tsvn:logtemplate
+ [dmMediaUploadifyerPlugin]
Added:
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary/actions/actions.class.php
===================================================================
---
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary/actions/actions.class.php
(rev 0)
+++
plugins/dmMediaUploadifyerPlugin/trunk/modules/dmMediaLibrary/actions/actions.class.php
2010-02-04 08:28:51 UTC (rev 27543)
@@ -0,0 +1,59 @@
+<?php
+
+require_once(dmOs::join(sfConfig::get('dm_admin_dir').'/modules/dmMediaLibrary/lib/BasedmMediaLibraryActions.class.php'));
+
+class dmMediaLibraryActions extends BasedmMediaLibraryActions
+{
+
+ /**
+ * Allows the upload of multiple files
+ *
+ * @param sfWebRequest $request
+ */
+ public function executeNewMultipleFile(dmWebRequest $request)
+ {
+ // create new media
+
+ $media = null;
+
+ $this->forward404Unless($folder =
dmDb::table('DmMediaFolder')->find($request->getParameter('folder_id')));
+
+ if (!$folder->isWritable())
+ {
+ $this->getUser()->logAlert($this->getI18n()->__('Folder %1% is not
writable', array('%1%' => $folder->fullPath)));
+ }
+
+ $form = new dmMediaUploadifyForm();
+ $form->setDefault('dm_media_folder_id', $folder->id);
+
+ if ($request->isMethod('post') && $form->bindAndValid($request))
+ {
+ $media = $form->save();
+
+ return $this->renderAsync('success');
+ }
+
+ $action = 'dmMediaLibrary/newMultipleFile?folder_id='.$folder->id;
+
+ $uploadify_widget = new sfWidgetFormDmUploadify();
+
+ return $this->renderText(
+ $form->render('.dm_form.list.little action="'.$action.'"') .
+ $this->getHelper()->tag('div.dm_encoded_assets.none', json_encode(array(
+ 'css' => $uploadify_widget->getStylesheets(),
+ 'js' => $uploadify_widget->getJavascripts(),
+ ))) . '<script type="text/javascript">__uploadify_widget_init()</script>'
+
+ );
+ }
+
+
+ public function executeUploadifyTest(dmWebRequest $request)
+ {
+ $out = 'test';
+
+ $out = print_r($request->getPostParameters(), true);
+ return $this->renderText($out);
+ }
+
+}
\ No newline at end of file
Deleted: plugins/dmMediaUploadifyerPlugin/trunk/web/css/default.css
===================================================================
--- plugins/dmMediaUploadifyerPlugin/trunk/web/css/default.css 2010-02-04
08:05:28 UTC (rev 27542)
+++ plugins/dmMediaUploadifyerPlugin/trunk/web/css/default.css 2010-02-04
08:28:51 UTC (rev 27543)
@@ -1,10 +0,0 @@
-body {
- font: 12px/16px Arial, Helvetica, sans-serif;
-}
-#fileQueue {
- width: 400px;
- height: 300px;
- overflow: auto;
- border: 1px solid #E5E5E5;
- margin-bottom: 10px;
-}
\ No newline at end of file
Modified: plugins/dmMediaUploadifyerPlugin/trunk/web/css/uploadify.css
===================================================================
--- plugins/dmMediaUploadifyerPlugin/trunk/web/css/uploadify.css
2010-02-04 08:05:28 UTC (rev 27542)
+++ plugins/dmMediaUploadifyerPlugin/trunk/web/css/uploadify.css
2010-02-04 08:28:51 UTC (rev 27543)
@@ -23,31 +23,31 @@
THE SOFTWARE.
*/
.uploadifyQueueItem {
- font: 11px Verdana, Geneva, sans-serif;
- border: 2px solid #E5E5E5;
- background-color: #F5F5F5;
- margin-top: 5px;
- padding: 10px;
- width: 350px;
+ font: 11px Verdana, Geneva, sans-serif;
+ border: 2px solid #E5E5E5;
+ background-color: #F5F5F5;
+ margin-top: 5px;
+ padding: 10px;
+ width: 215px;
}
.uploadifyError {
- border: 2px solid #FBCBBC !important;
- background-color: #FDE5DD !important;
+ border: 2px solid #FBCBBC !important;
+ background-color: #FDE5DD !important;
}
.uploadifyQueueItem .cancel {
- float: right;
+ float: right;
}
.uploadifyProgress {
- background-color: #FFFFFF;
- border-top: 1px solid #808080;
- border-left: 1px solid #808080;
- border-right: 1px solid #C5C5C5;
- border-bottom: 1px solid #C5C5C5;
- margin-top: 10px;
- width: 100%;
+ background-color: #FFFFFF;
+ border-top: 1px solid #808080;
+ border-left: 1px solid #808080;
+ border-right: 1px solid #C5C5C5;
+ border-bottom: 1px solid #C5C5C5;
+ margin-top: 10px;
+ width: 100%;
}
.uploadifyProgressBar {
- background-color: #0099FF;
- width: 1px;
- height: 3px;
+ background-color: #0099FF;
+ width: 1px;
+ height: 3px;
}
\ No newline at end of file
Added:
plugins/dmMediaUploadifyerPlugin/trunk/web/js/dmAdminMediaUploadifyCtrl.js
===================================================================
--- plugins/dmMediaUploadifyerPlugin/trunk/web/js/dmAdminMediaUploadifyCtrl.js
(rev 0)
+++ plugins/dmMediaUploadifyerPlugin/trunk/web/js/dmAdminMediaUploadifyCtrl.js
2010-02-04 08:28:51 UTC (rev 27543)
@@ -0,0 +1,42 @@
+(function($) {
+
+var $library = $("div.dm_media_library");
+
+$library.find("div.control a.uploadify_dialog_me").bind('click', function()
+{
+ var $dialog = $.dm.ctrl.ajaxDialog({
+ modal: true,
+ title: $(this).html(),
+ url: $(this).attr("href"),
+ width: 380
+ }).bind('dmAjaxResponse', function()
+ {
+ $dialog.prepare();
+ __uploadify_widget_init();
+ /*
+ $("form", $dialog).dmAjaxForm({
+ beforeSubmit: function()
+ {
+ $dialog.block();
+ },
+ success: function(data)
+ {
+ if (!data.match(/</))
+ {
+ $library.block();
+ location.href = data;
+ }
+ else
+ {
+ $dialog.unblock().html(data).trigger('dmAjaxResponse');
+ }
+ }
+ });
+ */
+ });
+
+ return false;
+});
+
+
+})(jQuery);
\ No newline at end of file
Added: plugins/dmMediaUploadifyerPlugin/trunk/web/js/sfWidgetFormDmUploadify.js
===================================================================
--- plugins/dmMediaUploadifyerPlugin/trunk/web/js/sfWidgetFormDmUploadify.js
(rev 0)
+++ plugins/dmMediaUploadifyerPlugin/trunk/web/js/sfWidgetFormDmUploadify.js
2010-02-04 08:28:51 UTC (rev 27543)
@@ -0,0 +1,107 @@
+_set_up_uploadify_widget = function($uploadified)
+{
+ $uploadified_form = $uploadified.parents('form');
+
+ var meta_data = $uploadified.metadata({type: 'html5'});
+
+
+ $field_holder = $uploadified.parent().clone().attr('id',
'a-new-and-unique-id')
+ $field_holder.children().remove('input, label')
+ $uploadified.parent().after(
+ $field_holder.append(
+ jQuery('<label/>', {
+ 'for' : 'fileQueue',
+ text : 'Upload Queue'
+ })
+ ).append(
+ jQuery('<div/>', {
+ id : 'fileQueue',
+ text: 'Empty',
+ css: {
+ 'max-height': '350px',
+ 'overflow': 'auto',
+ 'width': '70%',
+ 'float' : 'right'
+ }
+ })
+ ));
+
+
+ $uploadified.uploadify({
+ 'uploader' : '/dmMediaUploadifyerPlugin/swf/uploadify.swf',
+ 'script' : $uploadified_form.attr('action'),
+ 'cancelImg' : '/dmMediaUploadifyerPlugin/images/cancel.png',
+ 'queueID' : 'fileQueue',
+// 'simUploadLimit' : 3,
+ 'fileDataName' : $uploadified.attr('name'),
+ 'auto' : false,
+ 'multi' : true,
+ 'onComplete' : function(event, queueID, fileObj, response, data) {
+ //console.log(response);
+ //$uploadified.parent().after(response);
+ },
+ 'onError' : function(event, queueID, fileObj, errorObj) {
+ //console.log(errorObj.info);
+ }
+ });
+
+ console.log($uploadified.attr('name'));
+
+ $uploadified_form.bind('submit', function(e) {
+ //console.log('Live submit');
+ e.preventDefault();
+
+ varrr = jQuery.extend({
+ 'uploadify_session_name' : meta_data.session_name,
+ 'uploadify_session_id' : meta_data.session_id
+ },
+ __get_form_fields_as_object($uploadified_form)
+ );
+ //console.log(varrr);
+
+ $uploadified.uploadifySettings('scriptData', jQuery.extend({
+ 'uploadify_session_name' : meta_data.session_name,
+ 'uploadify_session_id' : meta_data.session_id
+ },
+ __get_form_fields_as_object($uploadified_form)
+ ));
+
+ $uploadified.uploadifyUpload();
+
+ return false;
+ });
+
+}
+
+__get_form_fields_as_object = function($form) {
+ fields = $form.serializeArray();
+ result = {};
+ jQuery.each(fields, function(i, field) {
+ if ('' !== field.value) {
+ result[ field.name ] = field.value;
+ }
+ });
+
+ return result;
+}
+
+__uploadify_widget_init = function()
+{
+ $uploadified = jQuery('input.uploadify_file_field');
+
+ $uploadified.each(function(){
+ _set_up_uploadify_widget($uploadified);
+ });
+
+}
+
+
+jQuery(document).ready(function() {
+
+// console.log('Loaded upladify stuff');
+
+ __uploadify_widget_init()
+ //watch_events(jQuery('input.uploadify_file_field').parents('form'))
+
+});
+
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.