/** * Init the uploader which is directly included in the webpage * * @return integer the uploader id */ protected function initUploader() { \JS::activate('cx'); // the uploader needs the framework $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader(); //create an uploader $uploadId = $uploader->getId(); $uploader->setCallback('fileSharingUploader'); $uploader->setOptions(array('id' => 'fileSharing_' . $uploadId, 'style' => 'display:none;')); $folderWidget = new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($_SESSION->getTempPath() . '/' . $uploadId, true); $folderWidgetId = $folderWidget->getId(); $extendedFileInputCode = <<<CODE <script type="text/javascript"> cx.ready(function() { var field = jQuery('#contactForm #file_upload'); //called if user clicks on the field var inputClicked = function() { jQuery('#fileSharing_{$uploadId}').trigger('click'); return false; }; jQuery('#fileSharing_{$uploadId}').hide(); field.bind('click', inputClicked).removeAttr('disabled'); }); //uploader javascript callback function function fileSharingUploader(callback) { angular.element('#mediaBrowserfolderWidget_{$folderWidgetId}').scope().refreshBrowser(); } </script> CODE; $this->objTemplate->setVariable(array('UPLOADER_CODE' => $uploader->getXHtml(), 'FILE_INPUT_CODE' => $extendedFileInputCode, 'FOLDER_WIDGET_CODE' => $folderWidget->getXHtml())); return $uploadId; // return the upload id }
/** * Inits the uploader when displaying a contact form. */ protected function initUploader($fieldId, $restrictUpload2SingleFile = true) { try { $cx = \Cx\Core\Core\Controller\Cx::instanciate(); $sessionObj = $cx->getComponent('Session')->getSession(); $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader(); //set instance name so we are able to catch the instance with js $uploader->setCallback('contactFormUploader_' . $fieldId); $cx = \Cx\Core\Core\Controller\Cx::instanciate(); // specifies the function to call when upload is finished. must be a static function $uploader->setFinishedCallback(array($cx->getCodeBaseCoreModulePath() . '/Contact/Controller/Contact.class.php', '\\Cx\\Core_Modules\\Contact\\Controller\\Contact', 'uploadFinished')); if ($restrictUpload2SingleFile) { $uploader->setData(array('singleFile' => $restrictUpload2SingleFile)); $uploader->setUploadLimit(1); } $uploaderId = $uploader->getId(); $uploader->setOptions(array('id' => 'contactUploader_' . $uploaderId, 'style' => 'display: none')); //initialize the widget displaying the folder contents $folderWidget = new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($_SESSION->getTempPath() . '/' . $uploaderId); $this->objTemplate->setVariable(array('CONTACT_UPLOADER_FOLDER_WIDGET_' . $fieldId => $folderWidget->getXhtml(), 'CONTACT_UPLOADER_ID_' . $fieldId => $uploaderId)); $folderWidgetId = $folderWidget->getId(); $strInputfield = $uploader->getXHtml(); $strInputfield .= <<<CODE <script type="text/javascript"> cx.ready(function() { jQuery('#contactFormFieldId_{$fieldId}').bind('click', function() { jQuery('#contactUploader_{$uploaderId}').trigger('click'); return false; }).removeAttr('disabled'); }); //uploader javascript callback function function contactFormUploader_{$fieldId}(callback) { angular.element('#mediaBrowserfolderWidget_{$folderWidgetId}').scope().refreshBrowser(); } </script> CODE; return $strInputfield; } catch (Exception $e) { return '<!-- failed initializing uploader, exception ' . get_class($e) . ' with message "' . $e->getMessage() . '" -->'; } }
/** * Get uploader code * * @param string $fieldKey uploadFieldKey * @param string $fieldName uploadFieldName * @param string $uploadCallBack upload callback function * @param boolean $allowImageOnly allow only images files * * @return string uploaderCode * @throws \Exception */ protected function getUploaderCode($fieldKey, $fieldName, $uploadCallBack = "uploadFinished", $allowImageOnly = true) { \cmsSession::getInstance(); $cx = \Cx\Core\Core\Controller\Cx::instanciate(); try { $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader(); $uploaderId = $uploader->getId(); $uploadOptions = array('id' => 'calendarUploader_' . $uploaderId, 'style' => 'display: none'); if ($allowImageOnly) { $uploadOptions['allowed-extensions'] = array('gif', 'jpg', 'png', 'jpeg'); } $uploader->setCallback($fieldName . 'JsCallback'); $uploader->setUploadLimit(1); $uploader->setOptions($uploadOptions); $uploader->setFinishedCallback(array($cx->getCodeBaseModulePath() . '/Calendar/Controller/Calendar.class.php', '\\Cx\\Modules\\Calendar\\Controller\\Calendar', $uploadCallBack)); $folderWidget = new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($_SESSION->getTempPath() . '/' . $uploaderId); $this->_objTpl->setVariable(array(strtoupper($fieldName) . '_WIDGET_CODE' => $folderWidget->getXHtml(), "{$this->moduleLangVar}_" . strtoupper($fieldKey) => $uploaderId)); $strJs = <<<JAVASCRIPT {$uploader->getXHtml()} <script type="text/javascript"> cx.ready(function() { //called if user clicks on the field jQuery('#{$fieldName}').bind('click', function() { jQuery('#calendarUploader_{$uploaderId}').trigger('click'); return false; }); }); //uploader javascript callback function function {$fieldName}JsCallback(callback) { angular.element('#mediaBrowserfolderWidget_{$folderWidget->getId()}').scope().refreshBrowser(); } </script> JAVASCRIPT; return $strJs; } catch (\Exception $e) { \DBG::msg('<!-- failed initializing uploader -->'); throw new \Exception("failed initializing uploader"); } }
/** * Overview Media Data * * @global array $_CONFIG * @global array $_ARRAYLANG * @return string parsed content */ function _overviewMedia() { global $_CONFIG, $_ARRAYLANG; switch ($this->getAct) { case 'download': $this->_downloadMedia(); break; case 'newDir': $this->_createDirectory($_POST['media_directory_name']); break; case 'upload': $this->_uploadFiles(); break; case 'rename': $this->_renameFiles(); break; case 'delete': $this->_deleteFiles(); break; default: } // tree navigation $tmp = $this->arrWebPaths[$this->archive]; if (substr($this->webPath, 0, strlen($tmp)) == $tmp) { $this->_objTpl->setVariable(array('MEDIA_TREE_NAV_MAIN' => "Home /", 'MEDIA_TREE_NAV_MAIN_HREF' => CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . $this->getCmd . '&path=' . rawurlencode($this->arrWebPaths[$this->archive]))); if (strlen($this->webPath) != strlen($tmp)) { $tmpPath = substr($this->webPath, -(strlen($this->webPath) - strlen($tmp))); $tmpPath = explode('/', $tmpPath); $tmpLink = ''; foreach ($tmpPath as $path) { if (!empty($path)) { $tmpLink .= $path . '/'; $this->_objTpl->setVariable(array('MEDIA_TREE_NAV_DIR' => $path, 'MEDIA_TREE_NAV_DIR_HREF' => CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . $this->getCmd . '&path=' . rawurlencode($this->arrWebPaths[$this->archive] . $tmpLink))); $this->_objTpl->parse('mediaTreeNavigation'); } } } } if (isset($_GET['deletefolder']) && ($_GET['deletefolder'] = "success")) { $this->_strOkMessage = $_ARRAYLANG['TXT_MEDIA_FOLDER_DELETED_SUCESSFULLY']; } if (!empty($_GET['highlightFiles'])) { $this->highlightName = array_merge($this->highlightName, array_map('basename', json_decode(contrexx_stripslashes(urldecode($_GET['highlightFiles']))))); } // media directory tree $i = 0; $dirTree = $this->_dirTree($this->path); $dirTree = $this->_sortDirTree($dirTree); foreach (array_keys($dirTree) as $key) { if (is_array($dirTree[$key]['icon'])) { for ($x = 0; $x < count($dirTree[$key]['icon']); $x++) { if (MediaLibrary::isIllegalFileName($dirTree[$key]['name'][$x])) { continue; } $class = $i % 2 ? 'row2' : 'row1'; // highlight if (in_array($dirTree[$key]['name'][$x], $this->highlightName)) { $class .= '" style="background-color: ' . $this->highlightColor . ';'; } if (!$this->manageAccessGranted()) { //if the user is not allowed to delete or rename files -- hide those blocks if ($this->_objTpl->blockExists('manage_access_option')) { $this->_objTpl->hideBlock('manage_access_option'); } } $this->_objTpl->setVariable(array('MEDIA_DIR_TREE_ROW' => $class, 'MEDIA_FILE_ICON' => $dirTree[$key]['icon'][$x], 'MEDIA_FILE_NAME' => $dirTree[$key]['name'][$x], 'MEDIA_FILE_SIZE' => $this->_formatSize($dirTree[$key]['size'][$x]), 'MEDIA_FILE_TYPE' => $this->_formatType($dirTree[$key]['type'][$x]), 'MEDIA_FILE_DATE' => $this->_formatDate($dirTree[$key]['date'][$x]), 'MEDIA_RENAME_TITLE' => $_ARRAYLANG['TXT_MEDIA_RENAME'], 'MEDIA_DELETE_TITLE' => $_ARRAYLANG['TXT_MEDIA_DELETE'])); $tmpHref = $delHref = ''; if ($key == 'dir') { $tmpHref = CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . $this->getCmd . '&path=' . rawurlencode($this->webPath . $dirTree[$key]['name'][$x] . '/'); $delHref = CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . $this->getCmd . '&act=delete&path=' . rawurlencode($this->webPath . $dirTree[$key]['name'][$x] . '/'); } elseif ($key == 'file') { $delHref = CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . $this->getCmd . '&act=delete&path=' . rawurlencode($this->webPath) . '&file=' . rawurlencode($dirTree[$key]['name'][$x]); if ($this->_isImage($this->path . $dirTree[$key]['name'][$x])) { $tmpSize = getimagesize($this->path . $dirTree[$key]['name'][$x]); $tmpHref = 'javascript: preview(\'' . $this->webPath . $dirTree[$key]['name'][$x] . '\', ' . $tmpSize[0] . ', ' . $tmpSize[1] . ');'; } else { $tmpHref = CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . '&act=download&path=' . rawurlencode($this->webPath) . '&file=' . rawurlencode($dirTree[$key]['name'][$x]); } } $this->_objTpl->setVariable(array('MEDIA_FILE_NAME_HREF' => $tmpHref, 'MEDIA_FILE_DELETE_HREF' => $delHref)); $this->_objTpl->parse('mediaDirectoryTree'); $i++; } } } // empty dir or php safe mode restriction if ($i == 0 && !@opendir($this->rootPath)) { $tmpMessage = !@opendir($this->path) ? 'PHP Safe Mode Restriction or wrong path' : $_ARRAYLANG['TXT_MEDIA_DIR_EMPTY']; $this->_objTpl->setVariable(array('TXT_MEDIA_DIR_EMPTY' => $tmpMessage, 'MEDIA_SELECT_STATUS' => ' disabled')); $this->_objTpl->parse('mediaEmptyDirectory'); } // parse variables $tmpHref = CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . $this->getCmd . '&path=' . rawurlencode($this->webPath); $tmpIcon = $this->_sortingIcons(); if ($this->_objTpl->blockExists('manage_access_header')) { if ($this->manageAccessGranted()) { $this->_objTpl->touchBlock('manage_access_header'); } else { $this->_objTpl->hideBlock('manage_access_header'); } } $this->_objTpl->setVariable(array('MEDIA_NAME_HREF' => $tmpHref . '&sort=name&sort_desc=' . ($this->sortBy == 'name' && !$this->sortDesc), 'MEDIA_SIZE_HREF' => $tmpHref . '&sort=size&sort_desc=' . ($this->sortBy == 'size' && !$this->sortDesc), 'MEDIA_TYPE_HREF' => $tmpHref . '&sort=type&sort_desc=' . ($this->sortBy == 'type' && !$this->sortDesc), 'MEDIA_DATE_HREF' => $tmpHref . '&sort=date&sort_desc=' . ($this->sortBy == 'date' && !$this->sortDesc), 'MEDIA_PERM_HREF' => $tmpHref . '&sort=perm&sort_desc=' . ($this->sortBy == 'perm' && !$this->sortDesc), 'TXT_MEDIA_FILE_NAME' => $_ARRAYLANG['TXT_MEDIA_FILE_NAME'], 'TXT_MEDIA_FILE_SIZE' => $_ARRAYLANG['TXT_MEDIA_FILE_SIZE'], 'TXT_MEDIA_FILE_TYPE' => $_ARRAYLANG['TXT_MEDIA_FILE_TYPE'], 'TXT_MEDIA_FILE_DATE' => $_ARRAYLANG['TXT_MEDIA_FILE_DATE'], 'TXT_MEDIA_FILE_PERM' => $_ARRAYLANG['TXT_MEDIA_FILE_PERM'], 'MEDIA_NAME_ICON' => $tmpIcon['name'], 'MEDIA_SIZE_ICON' => $tmpIcon['size'], 'MEDIA_TYPE_ICON' => $tmpIcon['type'], 'MEDIA_DATE_ICON' => $tmpIcon['date'], 'MEDIA_PERM_ICON' => $tmpIcon['perm'], 'MEDIA_JAVASCRIPT' => $this->_getJavaScriptCodePreview())); if (!$this->uploadAccessGranted()) { // if user not allowed to upload files and creating folders -- hide that blocks if ($this->_objTpl->blockExists('media_simple_file_upload')) { $this->_objTpl->hideBlock('media_simple_file_upload'); } if ($this->_objTpl->blockExists('media_advanced_file_upload')) { $this->_objTpl->hideBlock('media_advanced_file_upload'); } if ($this->_objTpl->blockExists('media_create_directory')) { $this->_objTpl->hideBlock('media_create_directory'); } } else { // forms for uploading files and creating folders if ($this->_objTpl->blockExists('media_simple_file_upload')) { //data we want to remember for handling the uploaded files $data = array('path' => $this->path, 'webPath' => $this->webPath); //new uploader $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader(); $uploader->setData($data); $uploader->setCallback('mediaCallbackJs'); $uploader->setFinishedCallback(array(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseCoreModulePath() . '/Media/Controller/MediaLibrary.class.php', '\\Cx\\Core_modules\\Media\\Controller\\MediaLibrary', 'uploadFinished')); $this->_objTpl->setVariable(array('TXT_MEDIA_ADD_NEW_FILE' => $_ARRAYLANG['TXT_MEDIA_ADD_NEW_FILE'], 'MEDIA_UPLOADER_CODE' => $uploader->getXHtml($_ARRAYLANG['TXT_MEDIA_BROWSE']), 'REDIRECT_URL' => '?section=' . $_REQUEST['section'] . '&path=' . contrexx_raw2encodedUrl($this->webPath))); $this->_objTpl->parse('media_simple_file_upload'); } if ($this->_objTpl->blockExists('media_advanced_file_upload')) { $this->_objTpl->hideBlock('media_advanced_file_upload'); } // create directory $this->_objTpl->setVariable(array('TXT_MEDIA_CREATE_DIRECTORY' => $_ARRAYLANG['TXT_MEDIA_CREATE_DIRECTORY'], 'TXT_MEDIA_CREATE_NEW_DIRECTORY' => $_ARRAYLANG['TXT_MEDIA_CREATE_NEW_DIRECTORY'], 'MEDIA_CREATE_DIRECTORY_URL' => CONTREXX_SCRIPT_PATH . '?section=' . $this->archive . $this->getCmd . '&act=newDir&path=' . $this->webPath)); $this->_objTpl->parse('media_create_directory'); //custom uploader \JS::activate('cx'); // the uploader needs the framework $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader(); //create an uploader $uploadId = $uploader->getId(); $uploader->setCallback('customUploader'); $uploader->setOptions(array('id' => 'custom_' . $uploadId)); $folderWidget = new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($_SESSION->getTempPath() . '/' . $uploadId, true); $folderWidgetId = $folderWidget->getId(); $extendedFileInputCode = <<<CODE <script type="text/javascript"> //uploader javascript callback function function customUploader(callback) { angular.element('#mediaBrowserfolderWidget_{$folderWidgetId}').scope().refreshBrowser(); } </script> CODE; $this->_objTpl->setVariable(array('UPLOADER_CODE' => $uploader->getXHtml(), 'UPLOADER_ID' => $uploadId, 'FILE_INPUT_CODE' => $extendedFileInputCode, 'FOLDER_WIDGET_CODE' => $folderWidget->getXHtml())); } }