Exemplo n.º 1
0
 /**
  * Load the MCL canvas layer library
  *
  * @return  array Scripts needed to load MCL
  */
 public static function mcl()
 {
     // Cant used compressed version as its not up to date
     $src = array('media/com_fabrik/js/lib/mcl/CANVAS.js', 'media/com_fabrik/js/lib/mcl/CanvasItem.js', 'media/com_fabrik/js/lib/mcl/Cmorph.js', 'media/com_fabrik/js/lib/mcl/Layer.js', 'media/com_fabrik/js/lib/mcl/LayerHash.js', 'media/com_fabrik/js/lib/mcl/Thread.js');
     if (!self::$mcl) {
         self::script($src);
         self::$mcl = true;
     }
     return $src;
 }
Exemplo n.º 2
0
 /**
  * Load the MCL canvas layer library
  *
  * @return  void
  */
 public static function mcl()
 {
     if (!self::$mcl) {
         $src = array('media/com_fabrik/js/lib/mcl/CANVAS.js', 'media/com_fabrik/js/lib/mcl/CanvasItem.js', 'media/com_fabrik/js/lib/mcl/Cmorph.js', 'media/com_fabrik/js/lib/mcl/Layer.js', 'media/com_fabrik/js/lib/mcl/LayerHash.js', 'media/com_fabrik/js/lib/mcl/Thread.js', 'media/com_fabrik/js/lib/canvas-extra.js');
         self::script($src);
         self::$mcl = true;
     }
 }
Exemplo n.º 3
0
 /**
  * Returns javascript which creates an instance of the class defined in formJavascriptClass()
  *
  * @param   int  $repeatCounter  Repeat group counter
  *
  * @return  array
  */
 public function elementJavascript($repeatCounter)
 {
     $params = $this->getParams();
     $id = $this->getHTMLId($repeatCounter);
     FabrikHelperHTML::mcl();
     $j3 = FabrikWorker::j3();
     $element = $this->getElement();
     $paramsKey = $this->getFullName(true, false);
     $paramsKey = Fabrikstring::rtrimword($paramsKey, $this->getElement()->name);
     $paramsKey .= 'params';
     $formData = $this->getFormModel()->data;
     $imgParams = FArrayHelper::getValue($formData, $paramsKey);
     // Above paramsKey stuff looks really wonky - lets test if null and use something which seems to build the correct key
     if (is_null($imgParams)) {
         $paramsKey = $this->getFullName(true, false) . '___params';
         $imgParams = FArrayHelper::getValue($formData, $paramsKey);
     }
     $value = $this->getValue(array(), $repeatCounter);
     $value = is_array($value) ? $value : FabrikWorker::JSONtoData($value, true);
     $value = $this->checkForSingleCropValue($value);
     // Repeat_image_repeat_image___params
     $rawValues = count($value) == 0 ? array() : array_fill(0, count($value), 0);
     $fileData = $this->getFormModel()->data;
     $rawKey = $this->getFullName(true, false) . '_raw';
     $rawValues = FArrayHelper::getValue($fileData, $rawKey, $rawValues);
     if (!is_array($rawValues)) {
         $rawValues = explode(GROUPSPLITTER, $rawValues);
     } else {
         /*
          * $$$ hugh - nasty hack for now, if repeat group with simple
          * uploads, all raw values are in an array in $rawValues[0]
          */
         if (is_array(FArrayHelper::getValue($rawValues, 0))) {
             $rawValues = $rawValues[0];
         }
     }
     if (!is_array($imgParams)) {
         $imgParams = explode(GROUPSPLITTER, $imgParams);
     }
     $oFiles = new stdClass();
     $iCounter = 0;
     // Failed validation for ajax upload elements
     if (is_array($value) && array_key_exists('id', $value)) {
         $imgParams = array_values($value['crop']);
         $value = array_keys($value['id']);
         $rawValues = $value;
     }
     for ($x = 0; $x < count($value); $x++) {
         if (is_array($value)) {
             if (array_key_exists($x, $value) && $value[$x] !== '') {
                 if (is_array($value[$x])) {
                     // From failed validation
                     foreach ($value[$x]['id'] as $tKey => $parts) {
                         $o = new stdClass();
                         $o->id = 'alreadyuploaded_' . $element->id . '_' . $iCounter;
                         $o->name = array_pop(explode(DIRECTORY_SEPARATOR, $tKey));
                         $o->path = $tKey;
                         if ($fileInfo = $this->getStorage()->getFileInfo($o->path)) {
                             $o->size = $fileInfo['filesize'];
                         } else {
                             $o->size = 'unknown';
                         }
                         $o->type = strstr($fileInfo['mime_type'], 'image/') ? 'image' : 'file';
                         $o->url = $this->getStorage()->pathToURL($tKey);
                         $o->recordid = $rawValues[$x];
                         $o->params = json_decode($value[$x]['crop'][$tKey]);
                         $oFiles->{$iCounter} = $o;
                         $iCounter++;
                     }
                 } else {
                     if (is_object($value[$x])) {
                         // Single crop image (not sure about the 0 settings in here)
                         $parts = explode(DIRECTORY_SEPARATOR, $value[$x]->file);
                         $o = new stdClass();
                         $o->id = 'alreadyuploaded_' . $element->id . '_0';
                         $o->name = array_pop($parts);
                         $o->path = $value[$x]->file;
                         if ($fileInfo = $this->getStorage()->getFileInfo($o->path)) {
                             $o->size = $fileInfo['filesize'];
                         } else {
                             $o->size = 'unknown';
                         }
                         $o->type = strstr($fileInfo['mime_type'], 'image/') ? 'image' : 'file';
                         $o->url = $this->getStorage()->pathToURL($value[$x]->file);
                         $o->recordid = 0;
                         $o->params = json_decode($value[$x]->params);
                         $oFiles->{$iCounter} = $o;
                         $iCounter++;
                     } else {
                         $parts = explode('/', $value[$x]);
                         $o = new stdClass();
                         $o->id = 'alreadyuploaded_' . $element->id . '_' . $rawValues[$x];
                         $o->name = array_pop($parts);
                         $o->path = $value[$x];
                         if ($fileInfo = $this->getStorage()->getFileInfo($o->path)) {
                             $o->size = $fileInfo['filesize'];
                         } else {
                             $o->size = 'unknown';
                         }
                         $o->type = strstr($fileInfo['mime_type'], 'image/') ? 'image' : 'file';
                         $o->url = $this->getStorage()->pathToURL($value[$x]);
                         $o->recordid = $rawValues[$x];
                         $o->params = json_decode(FArrayHelper::getValue($imgParams, $x, '{}'));
                         $oFiles->{$iCounter} = $o;
                         $iCounter++;
                     }
                 }
             }
         }
     }
     $opts = $this->getElementJSOptions($repeatCounter);
     $opts->id = $this->getId();
     if ($this->isJoin()) {
         $opts->isJoin = true;
         $opts->joinId = $this->getJoinModel()->getJoin()->id;
     }
     $opts->elid = $element->id;
     $opts->defaultImage = $params->get('default_image');
     $opts->folderSelect = $params->get('upload_allow_folderselect', 0);
     $opts->quality = (double) $params->get('image_quality') / 100;
     $opts->dir = JPATH_SITE . '/' . $params->get('ul_directory');
     $opts->ajax_upload = (bool) $params->get('ajax_upload', false);
     $opts->ajax_runtime = $params->get('ajax_runtime', 'html5');
     $opts->ajax_silverlight_path = COM_FABRIK_LIVESITE . 'plugins/fabrik_element/fileupload/lib/plupload/js/plupload.flash.swf';
     $opts->ajax_flash_path = COM_FABRIK_LIVESITE . 'plugins/fabrik_element/fileupload/lib/plupload/js/plupload.flash.swf';
     $opts->max_file_size = (double) $params->get('ul_max_file_size');
     $opts->device_capture = (double) $params->get('ul_device_capture');
     $opts->ajax_chunk_size = (int) $params->get('ajax_chunk_size', 0);
     $opts->filters = $this->ajaxFileFilters();
     $opts->crop = $this->canCrop();
     $opts->canvasSupport = FabrikHelperHTML::canvasSupport();
     $opts->elementName = $this->getFullName();
     $opts->cropwidth = (int) $params->get('fileupload_crop_width');
     $opts->cropheight = (int) $params->get('fileupload_crop_height');
     $opts->ajax_max = (int) $params->get('ajax_max', 4);
     $opts->dragdrop = true;
     $icon = $j3 ? 'picture' : 'image.png';
     $resize = $j3 ? 'expand-2' : 'resize.png';
     $opts->previewButton = FabrikHelperHTML::image($icon, 'form', @$this->tmpl, array('alt' => FText::_('PLG_ELEMENT_FILEUPLOAD_VIEW')));
     $opts->resizeButton = FabrikHelperHTML::image($resize, 'form', @$this->tmpl, array('alt' => FText::_('PLG_ELEMENT_FILEUPLOAD_RESIZE')));
     $opts->files = $oFiles;
     $opts->winWidth = (int) $params->get('win_width', 400);
     $opts->winHeight = (int) $params->get('win_height', 400);
     $opts->elementShortName = $element->name;
     $opts->listName = $this->getListModel()->getTable()->db_table_name;
     $opts->useWIP = (bool) $params->get('upload_use_wip', '0') == '1';
     $opts->page_url = COM_FABRIK_LIVESITE;
     JText::script('PLG_ELEMENT_FILEUPLOAD_MAX_UPLOAD_REACHED');
     JText::script('PLG_ELEMENT_FILEUPLOAD_DRAG_FILES_HERE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_UPLOAD_ALL_FILES');
     JText::script('PLG_ELEMENT_FILEUPLOAD_RESIZE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_CROP_AND_SCALE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_PREVIEW');
     JText::script('PLG_ELEMENT_FILEUPLOAD_CONFIRM_SOFT_DELETE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_CONFIRM_HARD_DELETE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_FILE_TOO_LARGE_SHORT');
     return array('FbFileUpload', $id, $opts);
 }
Exemplo n.º 4
0
 /**
  * return the javascript to create an instance of the class defined in formJavascriptClass
  * @return string javascript to create instance. Instance name must be 'el'
  */
 function elementJavascript($repeatCounter)
 {
     $params = $this->getParams();
     $id = $this->getHTMLId($repeatCounter);
     //if ((int)$params->get('fileupload_crop', 0) == 1) {
     //FabrikHelperHTML::script('media/com_fabrik/js/mcl-min.js');
     FabrikHelperHTML::mcl();
     /* 	$src = array('media/com_fabrik/js/lib/mcl/CANVAS.js', 'media/com_fabrik/js/lib/mcl/CanvasItem.js',
     			'media/com_fabrik/js/lib/mcl/Cmorph.js', 'media/com_fabrik/js/lib/mcl/Layer.js',
     		'media/com_fabrik/js/lib/mcl/LayerHash.js', 'media/com_fabrik/js/lib/mcl/Thread.js',
     		'media/com_fabrik/js/lib/canvas-extra.js'
     		);
     		FabrikHelperHTML::script($src); */
     //}
     $element = $this->getElement();
     $paramsKey = $this->getFullName(false, true, false);
     $paramsKey = Fabrikstring::rtrimword($paramsKey, $this->getElement()->name);
     $paramsKey .= 'params';
     $formData = $this->getForm()->_data;
     $imgParams = JArrayHelper::getValue($formData, $paramsKey);
     $value = $this->getValue(array(), $repeatCounter);
     $value = is_array($value) ? $value : FabrikWorker::JSONtoData($value, true);
     $value = $this->checkForSingleCropValue($value);
     //repeat_image_repeat_image___params
     $rawvalues = count($value) == 0 ? array() : array_fill(0, count($value), 0);
     $fdata = $this->getForm()->_data;
     $rawkey = $this->getFullName(false, true, false) . '_raw';
     $rawvalues = JArrayHelper::getValue($fdata, $rawkey, $rawvalues);
     if (!is_array($rawvalues)) {
         $rawvalues = explode(GROUPSPLITTER, $rawvalues);
     }
     if (!is_array($imgParams)) {
         $imgParams = explode(GROUPSPLITTER, $imgParams);
     }
     $oFiles = new stdClass();
     $iCounter = 0;
     for ($x = 0; $x < count($value); $x++) {
         if (is_array($value)) {
             if (array_key_exists($x, $value) && $value[$x] !== '') {
                 if (is_array($value[$x])) {
                     //from failed validation
                     foreach ($value[$x]['id'] as $tkey => $parts) {
                         $o = new stdClass();
                         $o->id = 'alreadyuploaded_' . $element->id . '_' . $iCounter;
                         //$rawvalues[$x];
                         $o->name = array_pop(explode(DS, $tkey));
                         $o->path = $tkey;
                         $o->url = $this->getStorage()->pathToURL($tkey);
                         $o->recordid = $rawvalues[$x];
                         $o->params = json_decode($value[$x]['crop'][$tkey]);
                         $oFiles->{$iCounter} = $o;
                         $iCounter++;
                     }
                 } else {
                     if (is_object($value[$x])) {
                         //single crop image (not sure about the 0 settings in here)
                         $parts = explode(DS, $value[$x]->file);
                         $o = new stdClass();
                         $o->id = 'alreadyuploaded_' . $element->id . '_0';
                         $o->name = array_pop($parts);
                         $o->path = $value[$x]->file;
                         $o->url = $this->getStorage()->pathToURL($value[$x]->file);
                         $o->recordid = 0;
                         $o->params = json_decode($value[$x]->params);
                         $oFiles->{$iCounter} = $o;
                         $iCounter++;
                     } else {
                         $parts = explode(DS, $value[$x]);
                         $o = new stdClass();
                         $o->id = 'alreadyuploaded_' . $element->id . '_' . $rawvalues[$x];
                         $o->name = array_pop($parts);
                         $o->path = $value[$x];
                         $o->url = $this->getStorage()->pathToURL($value[$x]);
                         $o->recordid = $rawvalues[$x];
                         $o->params = json_decode(JArrayHelper::getValue($imgParams, $x, '{}'));
                         $oFiles->{$iCounter} = $o;
                         $iCounter++;
                     }
                 }
             }
         }
     }
     $opts = $this->getElementJSOptions($repeatCounter);
     $opts->id = $this->_id;
     if ($this->isJoin()) {
         $opts->isJoin = true;
         $opts->joinId = $this->getJoinModel()->getJoin()->id;
     }
     $opts->elid = $element->id;
     $opts->defaultImage = $params->get('default_image');
     $opts->folderSelect = $params->get('upload_allow_folderselect', 0);
     $opts->dir = JPATH_SITE . DS . $params->get('ul_directory');
     $opts->ajax_upload = (bool) $params->get('ajax_upload', false);
     $opts->ajax_runtime = $params->get('ajax_runtime', 'html5');
     $opts->max_file_size = $params->get('ul_max_file_size');
     $opts->ajax_chunk_size = (int) $params->get('ajax_chunk_size', 0);
     $opts->crop = (int) $params->get('fileupload_crop', 0);
     $opts->elementName = $this->getFullName(true, true, true);
     $opts->cropwidth = (int) $params->get('fileupload_crop_width');
     $opts->cropheight = (int) $params->get('fileupload_crop_height');
     $opts->ajax_max = (int) $params->get('ajax_max', 4);
     $opts->dragdrop = true;
     $opts->previewButton = FabrikHelperHTML::image('image.png', 'form', @$this->tmpl, array('alt' => JText::_('PLG_ELEMENT_FILEUPLOAD_VIEW')));
     $opts->resizeButton = FabrikHelperHTML::image('resize.png', 'form', @$this->tmpl, array('alt' => JText::_('PLG_ELEMENT_FILEUPLOAD_RESIZE')));
     $opts->files = $oFiles;
     $opts = json_encode($opts);
     JText::script('PLG_ELEMENT_FILEUPLOAD_MAX_UPLOAD_REACHED');
     JText::script('PLG_ELEMENT_FILEUPLOAD_DRAG_FILES_HERE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_UPLOAD_ALL_FILES');
     JText::script('PLG_ELEMENT_FILEUPLOAD_RESIZE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_CROP_AND_SCALE');
     JText::script('PLG_ELEMENT_FILEUPLOAD_PREVIEW');
     return "new FbFileUpload('{$id}', {$opts})";
 }