PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/rmcommon/trunk/class/flashuploader.php

http://bitcero-modules.googlecode.com/
PHP | 141 lines | 103 code | 16 blank | 22 comment | 5 complexity | b6650bc73bc79e4048f0c51656da7a20 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: flashuploader.php 999 2012-07-02 03:53:17Z i.bitcero $
  3. // --------------------------------------------------------------
  4. // Red México Common Utilities
  5. // A framework for Red México Modules
  6. // Author: Eduardo Cortés <i.bitcero@gmail.com>
  7. // Email: i.bitcero@gmail.com
  8. // License: GPL 2.0
  9. // --------------------------------------------------------------
  10. class RMFlashUploader
  11. {
  12. private $settings = array();
  13. public $name = '';
  14. /**
  15. * Constructor
  16. *
  17. * @param string Name of instance
  18. * @param string Target uploader url (e.g. uploader.php)
  19. * @param array SWFUploader settings
  20. * @return RMFlashUploader
  21. */
  22. public function __construct($name, $url, $settings = array()){
  23. // Generate settings for uploadify
  24. $this->settings = array(
  25. 'swf' => RMCURL.'/include/uploadify.swf',
  26. 'uploader' => $url,
  27. 'auto' => false,
  28. 'buttonClass' => '',
  29. 'buttonCursor' => 'hand',
  30. 'buttonImage' => null,
  31. 'buttonText' => __('Select Files','rmcommon'),
  32. 'checkExisting' => false,
  33. 'debug' => false,
  34. 'fileObjName' => 'Filedata',
  35. 'fileSizeLimit' => '512KB',
  36. 'fileTypeDesc' => __('All Files','rmcommon'),
  37. 'fileTypeExts' => '*.*',
  38. 'formData' => array(),
  39. 'height' => 30,
  40. 'method' => 'post',
  41. 'multi' => true,
  42. 'overrideEvents' => '',
  43. 'preventCaching' => true,
  44. 'progressData' => 'percentage',
  45. 'queueID' => false,
  46. 'queueSizeLimit' => 100,
  47. 'removeCompleted' => true,
  48. 'removeTimeout' => 2,
  49. 'requeueErrors' => false,
  50. 'successTimeout' => 30,
  51. 'uploadLimit' => 999,
  52. 'width' => 120,
  53. 'onCancel' => '',
  54. 'onClearQueue' => '',
  55. 'onDestroy' => '',
  56. 'onDialogClose' => '',
  57. 'onDialogOpen' => '',
  58. 'onDisable' => '',
  59. 'onEnable' => '',
  60. 'onFallback' => '',
  61. 'onInit' => '',
  62. 'onQueueComplete' => '',
  63. 'onSelect' => '',
  64. 'onSelectError' => '',
  65. 'onSWFReady' => '',
  66. 'onUploadComplete' => '',
  67. 'onUploadError' => '',
  68. 'onUploadProgress' => '',
  69. 'onUploadStart' => '',
  70. 'onUploadSuccess' => ''
  71. );
  72. foreach ($settings as $key => $value){
  73. if (!isset($this->settings[$key])) continue;
  74. $this->settings[$key] = $value;
  75. }
  76. $this->name = $name;
  77. }
  78. public function add_setting($name, $value){
  79. $convert = array(
  80. 'scriptData' => 'formData',
  81. 'onComplete' => 'onUploadComplete',
  82. 'onAllComplete' => 'onQueueComplete',
  83. 'fileExt' => 'fileTypeExts',
  84. 'fileDesc' => 'fileTypeDesc',
  85. 'buttonImg' => 'buttonImage',
  86. 'fileDataName' => 'fileObjName',
  87. 'checkScript' => 'checkExisting',
  88. 'sizeLimit' => 'fileSizeLimit',
  89. 'onOpen' => 'onDialogOpen',
  90. 'onError' => 'onUploadError',
  91. 'onProgress' => 'onUploadProgress'
  92. );
  93. if(isset($convert[$name])) $name = $convert[$name];
  94. if (!isset($this->settings[$name])) return false;
  95. $this->settings[$name] = $value;
  96. return true;
  97. }
  98. public function get_setting($name){
  99. if (!isset($this->settings[$name])) return false;
  100. return $this->settings[$name];
  101. }
  102. /**
  103. * Add several settings items at once
  104. *
  105. * @param array $settings
  106. */
  107. public function add_settings($settings){
  108. foreach ($settings as $key => $value){
  109. if (!isset($this->settings[$key])) continue;
  110. $this->settings[$key] = $value;
  111. }
  112. }
  113. public function settings(){
  114. return $this->settings;
  115. }
  116. public function render(){
  117. RMTemplate::get()->add_local_script('swfobject.js', 'rmcommon', 'include');
  118. RMTemplate::get()->add_local_script('jquery.uploadify.js', 'rmcommon', 'include');
  119. RMTemplate::get()->add_style('uploadify.css', 'rmcommon');
  120. ob_start();
  121. include RMTemplate::get()->get_template('uploadify.js.php', 'module', 'rmcommon');
  122. $script = ob_get_clean();
  123. return $script;
  124. }
  125. }