Exemple #1
0
    /**
     * Overview Media Data
     *
     * @global     array     $_ARRAYLANG
     * @return    string    parsed content
     */
    function _overviewMedia()
    {
        global $_ARRAYLANG, $_CORELANG;
        $searchTerm = $this->isSearchActivated() && !empty($_GET['term']) ? \FWValidator::getCleanFileName(contrexx_input2raw($_GET['term'])) : '';
        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 (!empty($_GET['highlightFiles'])) {
            $this->highlightName = array_merge($this->highlightName, array_map('basename', json_decode(contrexx_stripslashes(urldecode($_GET['highlightFiles'])))));
        }
        // media directory tree
        $dirTree = array();
        $this->getDirectoryTree($this->path, $searchTerm, $dirTree, !empty($searchTerm));
        $dirTree = $this->_sortDirTree($dirTree);
        $deleteUrl = clone \Cx\Core\Core\Controller\Cx::instanciate()->getRequest()->getUrl();
        $deleteUrl->setParam('act', null);
        $previewUrl = clone $deleteUrl;
        $renameUrl = clone $deleteUrl;
        $redirect = urlencode(base64_encode($deleteUrl->toString(false)));
        $renameUrl->setParam('redirect', $redirect);
        $deleteUrl->setParam('redirect', $redirect);
        $renameUrl->setParam('act', 'rename');
        $deleteUrl->setParam('act', 'delete');
        $i = 0;
        foreach (array_keys($dirTree) as $key) {
            if (!is_array($dirTree[$key]['icon'])) {
                continue;
            }
            $mediaCount = count($dirTree[$key]['icon']);
            for ($x = 0; $x < $mediaCount; $x++) {
                $fileName = $dirTree[$key]['name'][$x];
                if (MediaLibrary::isIllegalFileName($fileName)) {
                    continue;
                }
                $class = $i % 2 ? 'row2' : 'row1';
                // highlight
                if (in_array($fileName, $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' => $fileName, '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']));
                $image = false;
                $imagePreview = '';
                $mediaPath = $this->path;
                $mediaWebPath = $this->webPath;
                if (!empty($searchTerm)) {
                    $mediaPath = $dirTree[$key]['path'][$x] . '/';
                    $mediaWebPath = $mediaPath;
                    \Cx\Lib\FileSystem\FileSystem::path_relative_to_root($mediaWebPath);
                    $mediaWebPath = '/' . $mediaWebPath;
                    // Filesysystem removes the beginning slash(/)
                }
                $file = rawurlencode($fileName);
                if ($key == 'dir') {
                    $path = rawurlencode($mediaWebPath . $fileName . '/');
                    $previewUrl->setParam('act', null);
                    $previewUrl->setParam('file', null);
                    $previewUrl->setParam('path', $path);
                } elseif ($key == 'file') {
                    $path = rawurlencode($mediaWebPath);
                    $filePath = $mediaPath . $fileName;
                    if ($this->_isImage($filePath)) {
                        $image = true;
                        $tmpSize = getimagesize($filePath);
                        $imagePreview = 'javascript: preview(\'' . $mediaWebPath . $fileName . '\', ' . $tmpSize[0] . ', ' . $tmpSize[1] . ');';
                    } else {
                        $previewUrl->setParam('act', 'download');
                        $previewUrl->setParam('path', $path);
                        $previewUrl->setParam('file', $file);
                    }
                }
                $deleteUrl->setParam('path', $path);
                $deleteUrl->setParam('file', $key == 'dir' ? null : $file);
                $renameUrl->setParam('path', rawurlencode($mediaWebPath));
                $renameUrl->setParam('file', $file);
                $this->_objTpl->setVariable(array('MEDIA_FILE_NAME_HREF' => $image ? $imagePreview : $previewUrl->toString(false), 'MEDIA_FILE_RENAME_HREF' => $renameUrl->toString(false), 'MEDIA_FILE_DELETE_HREF' => $deleteUrl->toString(false)));
                $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 . (!empty($searchTerm) ? '&amp;term=' . contrexx_raw2xhtml($searchTerm) : '') . '&amp;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 . '&amp;sort=name&amp;sort_desc=' . ($this->sortBy == 'name' && !$this->sortDesc), 'MEDIA_SIZE_HREF' => $tmpHref . '&amp;sort=size&amp;sort_desc=' . ($this->sortBy == 'size' && !$this->sortDesc), 'MEDIA_TYPE_HREF' => $tmpHref . '&amp;sort=type&amp;sort_desc=' . ($this->sortBy == 'type' && !$this->sortDesc), 'MEDIA_DATE_HREF' => $tmpHref . '&amp;sort=date&amp;sort_desc=' . ($this->sortBy == 'date' && !$this->sortDesc), 'MEDIA_PERM_HREF' => $tmpHref . '&amp;sort=perm&amp;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_ARCHIVE_NAME' => $this->archive, 'MEDIA_ARCHIVE_PATH' => rawurlencode($this->webPath), 'MEDIA_JAVASCRIPT' => $this->_getJavaScriptCodePreview(), 'MEDIA_SEARCH_TERM' => contrexx_raw2xhtml(rawurldecode($searchTerm)), 'TXT_MEDIA_SEARCH' => $_CORELANG['TXT_SEARCH'], 'TXT_MEDIA_SEARCH_TERM' => $_ARRAYLANG['TXT_MEDIA_SEARCH_TERM']));
        if ($this->_objTpl->blockExists('media_archive_search_form') && !$this->isSearchActivated()) {
            $this->_objTpl->hideBlock('media_archive_search_form');
        }
        // Hide folder creation and file upload functionalies,
        // when permission denied and on search mode
        if (!$this->uploadAccessGranted() || !empty($searchTerm)) {
            // 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 . '&amp;act=newDir&amp;path=' . rawurlencode($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));
            $cx = \Cx\Core\Core\Controller\Cx::instanciate();
            $folderWidget = new \Cx\Core_Modules\MediaBrowser\Model\Entity\FolderWidget($cx->getComponent('Session')->getSession()->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()));
        }
    }
 /**
  * Overview Media Data
  *
  * @global     array     $_ARRAYLANG
  * @global     array     $_CONFIG
  * @global     array     $_CORELANG
  * @return    string    parsed content
  */
 function _overviewMedia()
 {
     global $_ARRAYLANG, $_CONFIG, $_CORELANG, $objDatabase;
     \JS::activate('shadowbox');
     $this->_objTpl->loadTemplateFile('module_media.html', true, true);
     switch ($this->archive) {
         case 'themes':
             $this->pageTitle = $_ARRAYLANG['TXT_MEDIA_LAYOUT'];
             break;
         case 'content':
             $this->pageTitle = $_ARRAYLANG['TXT_IMAGE_ADMINISTRATION'];
             break;
         case 'Contact':
             $this->pageTitle = $_ARRAYLANG['TXT_FILE_UPLOADS'];
             break;
         case 'attach':
         case 'Access':
         case 'Blog':
         case 'Calendar':
         case 'Downloads':
         case 'Gallery':
         case 'MediaDir':
         case 'Podcast':
         case 'Shop':
             $archives = array('attach' => 'TXT_FILE_UPLOADS', 'Shop' => 'TXT_IMAGE_SHOP', 'Gallery' => 'TXT_GALLERY_TITLE', 'Access' => 'TXT_USER_ADMINISTRATION', 'MediaDir' => 'TXT_MEDIADIR_MODULE', 'Downloads' => 'TXT_DOWNLOADS', 'Calendar' => 'TXT_CALENDAR', 'Podcast' => 'TXT_PODCAST', 'Blog' => 'TXT_BLOG_MODULE');
             $moduleMatchTable = array('attach' => 'core');
             $subnavigation = '
                 <div id="subnavbar_level2">
                     <ul>';
             $license = \Cx\Core_Modules\License\License::getCached($_CONFIG, $objDatabase);
             $license->check();
             foreach ($archives as $archive => $txtKey) {
                 $moduleName = $archive;
                 if (isset($moduleMatchTable[$archive])) {
                     $moduleName = $moduleMatchTable[$archive];
                 }
                 if (!$license->isInLegalComponents($moduleName)) {
                     \DBG::msg('Module "' . $archive . '" is deactivated');
                     continue;
                 }
                 $subnavigation .= '
                         <li><a href="index.php?cmd=Media&amp;archive=' . $archive . '" class="' . ($this->archive == $archive ? 'active' : '') . '">' . $_ARRAYLANG[$txtKey] . '</a></li>';
             }
             $subnavigation .= '
                     </ul>
                 </div>';
             $this->_objTpl->setVariable('CONTENT_SUBNAVIGATION', $subnavigation);
         default:
             $this->pageTitle = $_ARRAYLANG['TXT_MEDIA_OVERVIEW'];
             if ($this->archive == "FileSharing") {
                 \Cx\Modules\FileSharing\Controller\FileSharingLib::cleanUp();
             }
             break;
     }
     $searchTerm = !empty($_GET['term']) ? \FWValidator::getCleanFileName(contrexx_input2raw($_GET['term'])) : '';
     // cut, copy and paste session
     if (isset($_SESSION['mediaCutFile'])) {
         $tmpArray = array();
         foreach ($_SESSION['mediaCutFile'][2] as $tmp) {
             if (file_exists($_SESSION['mediaCutFile'][0] . $tmp)) {
                 $tmpArray[] = $tmp;
             }
         }
         if (count($tmpArray) > 0) {
             $_SESSION['mediaCutFile'][0] = $_SESSION['mediaCutFile'][0];
             $_SESSION['mediaCutFile'][1] = $_SESSION['mediaCutFile'][1];
             $_SESSION['mediaCutFile'][2] = $tmpArray;
         } else {
             unset($_SESSION['mediaCutFile']);
         }
     }
     if (isset($_SESSION['mediaCopyFile'])) {
         $tmpArray = array();
         foreach ($_SESSION['mediaCopyFile'][2] as $tmp) {
             if (file_exists($_SESSION['mediaCopyFile'][0] . $tmp)) {
                 $tmpArray[] = $tmp;
             }
         }
         if (count($tmpArray) > 0) {
             $_SESSION['mediaCopyFile'][0] = $_SESSION['mediaCopyFile'][0];
             $_SESSION['mediaCopyFile'][1] = $_SESSION['mediaCopyFile'][1];
             $_SESSION['mediaCopyFile'][2] = $tmpArray;
         } else {
             unset($_SESSION['mediaCopyFile']);
         }
     }
     // tree navigation
     $tmp = $this->arrWebPaths[$this->archive];
     if (substr($this->webPath, 0, strlen($tmp)) == $tmp) {
         $this->_objTpl->setVariable(array('MEDIA_TREE_NAV_MAIN' => 'http://' . $_SERVER['HTTP_HOST'] . $this->arrWebPaths[$this->archive], 'MEDIA_TREE_NAV_MAIN_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;path=' . $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' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;path=' . $this->arrWebPaths[$this->archive] . $tmpLink));
                     $this->_objTpl->parse('mediaTreeNavigation');
                 }
             }
         }
     }
     //check if a finished upload caused reloading of the page.
     //if yes, we know the added files and want to highlight them
     if (!empty($_GET['highlightUploadId'])) {
         $key = 'media_upload_files_' . $_GET['highlightUploadId'];
         if (isset($_SESSION[$key])) {
             $sessionHighlightCandidates = $_SESSION[$key]->toArray();
             //an array with the filenames, set in mediaLib::uploadFinished
         }
         //clean up session; we do only highlight once
         unset($_SESSION[$key]);
         if (is_array($sessionHighlightCandidates)) {
             //make sure we don't cause any unexpected behaviour if we lost the session data
             $this->highlightName = $sessionHighlightCandidates;
         }
     }
     // Check if an image has been edited.
     // If yes, we know the edited file and want to highlight them.
     if (!empty($_GET['editedImage'])) {
         \Cx\Core\Core\Controller\Cx::instanciate()->getMediaSourceManager()->getThumbnailGenerator()->createThumbnailFromPath($this->path . $_GET['editedImage'], true);
         $this->highlightName[] = $_GET['editedImage'];
     }
     if (!empty($_SESSION['media_highlight_name'])) {
         $this->highlightName = $_SESSION['media_highlight_name']->toArray();
         unset($_SESSION['media_highlight_name']);
     }
     // media directory tree
     $i = 0;
     $dirTree = array();
     $this->getDirectoryTree($this->path, $searchTerm, $dirTree, !empty($searchTerm));
     $dirTree = $this->_sortDirTree($dirTree);
     $deleteUrl = clone \Cx\Core\Core\Controller\Cx::instanciate()->getRequest()->getUrl();
     $deleteUrl->setParam('act', null);
     $previewUrl = clone $deleteUrl;
     $renameUrl = clone $deleteUrl;
     $editUrl = clone $deleteUrl;
     $redirect = urlencode(base64_encode($deleteUrl->toString(false)));
     $renameUrl->setParam('redirect', $redirect);
     $deleteUrl->setParam('redirect', $redirect);
     $editUrl->setParam('redirect', $redirect);
     $renameUrl->setParam('act', 'rename');
     $deleteUrl->setParam('act', 'delete');
     $editUrl->setParam('act', 'edit');
     foreach (array_keys($dirTree) as $key) {
         if (!is_array($dirTree[$key]['icon'])) {
             continue;
         }
         $mediaCount = count($dirTree[$key]['icon']);
         for ($x = 0; $x < $mediaCount; $x++) {
             $fileName = $dirTree[$key]['name'][$x];
             if (MediaLibrary::isIllegalFileName($fileName)) {
                 continue;
             }
             // colors
             $class = $i % 2 ? 'row2' : 'row1';
             if (in_array($fileName, $this->highlightName)) {
                 // highlight
                 $class .= '" style="background-color: ' . $this->highlightColor . ';';
             }
             if (isset($_SESSION['mediaCutFile']) && !empty($_SESSION['mediaCutFile']) && $this->webPath == $_SESSION['mediaCutFile'][1] && in_array($fileName, $_SESSION['mediaCutFile'][2])) {
                 // cut
                 $class .= '" style="background-color: ' . $this->highlightCCColor . ';';
             }
             if (isset($_SESSION['mediaCopyFile']) && !empty($_SESSION['mediaCopyFile']) && $this->webPath == $_SESSION['mediaCopyFile'][1] && in_array($fileName, $_SESSION['mediaCopyFile'][2])) {
                 // copy
                 $class .= '" style="background-color: ' . $this->highlightCCColor . ';';
             }
             $this->_objTpl->setVariable(array('MEDIA_DIR_TREE_ROW' => $class, 'MEDIA_FILE_ICON' => $dirTree[$key]['icon'][$x], 'MEDIA_FILE_NAME' => $fileName, '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_FILE_PERM' => $this->_formatPerm($dirTree[$key]['perm'][$x], $key)));
             $image = false;
             $imagePreview = '';
             $mediaPath = $this->path;
             $mediaWebPath = $this->webPath;
             if (!empty($searchTerm)) {
                 $mediaPath = $dirTree[$key]['path'][$x] . '/';
                 $mediaWebPath = $mediaPath;
                 \Cx\Lib\FileSystem\FileSystem::path_relative_to_root($mediaWebPath);
                 $mediaWebPath = '/' . $mediaWebPath;
                 // Filesystem removes the beginning slash(/)
             }
             $file = rawurlencode($fileName);
             if ($key == 'dir') {
                 $path = rawurlencode($mediaWebPath . $fileName . '/');
                 $previewUrl->setParam('act', null);
                 $previewUrl->setParam('file', null);
             } elseif ($key == 'file') {
                 $path = rawurlencode($mediaWebPath);
                 $filePath = $mediaPath . $fileName;
                 if ($this->_isImage($filePath)) {
                     $image = true;
                     $imagePreview = 'javascript:expandcontent(\'preview_' . $fileName . '\');';
                 } else {
                     $previewUrl->setParam('act', 'download');
                     $previewUrl->setParam('file', $file);
                 }
             }
             $deleteUrl->setParam('path', rawurlencode($mediaWebPath));
             $deleteUrl->setParam('file', $file);
             $renameUrl->setParam('path', rawurlencode($mediaWebPath));
             $renameUrl->setParam('file', $file);
             $editUrl->setParam('path', rawurlencode($mediaWebPath));
             $editUrl->setParam('file', $file);
             if (!$image) {
                 $previewUrl->setParam('path', $path);
             }
             // show thumbnail
             if ($image) {
                 // make thumbnail if it doesn't exist
                 $tmpSize = @getimagesize($mediaPath . $fileName);
                 $thumbnails = \Cx\Core\Core\Controller\Cx::instanciate()->getMediaSourceManager()->getThumbnailGenerator()->createThumbnailFromPath($mediaPath . $fileName);
                 $thumb = $mediaWebPath . $thumbnails[0];
                 if (in_array($fileName, $this->highlightName)) {
                     $thumb .= '?lastAccess=' . fileatime($mediaPath . $fileName);
                 }
                 $this->_objTpl->setVariable(array('MEDIA_FILE_NAME_SIZE' => $tmpSize[0] . ' x ' . $tmpSize[1], 'MEDIA_FILE_NAME_PRE' => 'preview_' . $fileName, 'MEDIA_FILE_NAME_IMG_HREF' => $mediaWebPath . $fileName, 'MEDIA_FILE_NAME_IMG_SRC' => $thumb, 'MEDIA_FILE_NAME_IMG_SIZE' => $thumbnails[0]['size']));
                 $this->_objTpl->parse('mediaShowThumbnail');
                 $this->_objTpl->setVariable(array('MEDIA_FILE_EDIT_HREF' => $editUrl->toString(false), 'MEDIA_EDIT' => $_ARRAYLANG['TXT_MEDIA_EDIT']));
                 $this->_objTpl->parse('mediaImageEdit');
             }
             $this->_objTpl->setVariable(array('MEDIA_FILE_NAME_HREF' => $image ? $imagePreview : $previewUrl->toString(false), 'MEDIA_FILE_RENAME_HREF' => $renameUrl->toString(false), 'MEDIA_FILE_DELETE_HREF' => $deleteUrl->toString(false), 'MEDIA_FILE_FILESHARING_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=filesharing&amp;path=' . $mediaWebPath . '&amp;file=' . $fileName, 'MEDIA_FILESHARING_STATE' => \Cx\Modules\FileSharing\Controller\FileSharingLib::isShared(null, (isset($_GET['path']) ? $_GET['path'] : ASCMS_FILESHARING_WEB_PATH . '/') . $fileName) ? '_green' : '_red', 'MEDIA_RENAME' => $_ARRAYLANG['TXT_MEDIA_RENAME'], 'MEDIA_DELETE' => $_ARRAYLANG['TXT_MEDIA_DELETE'], 'MEDIA_FILESHARING' => $_ARRAYLANG['TXT_FILESHARING_MODULE']));
             if ($this->archive == "FileSharing" && !is_dir($mediaPath . $fileName)) {
                 $this->_objTpl->parse('mediaFilesharing');
             } else {
                 $this->_objTpl->hideBlock('mediaFilesharing');
             }
             $this->_objTpl->parse('mediaDirectoryTree');
             $i++;
         }
     }
     // empty dir or php safe mode restriction
     if ($i == 0 || !@opendir($this->path)) {
         $tmpMessage = $_ARRAYLANG['TXT_MEDIA_DIR_EMPTY'];
         if (!@opendir($this->path)) {
             $tmpMessage = 'PHP Safe Mode Restriction!';
         }
         $this->_objTpl->setVariable(array('TXT_MEDIA_DIR_EMPTY' => $tmpMessage, 'MEDIA_SELECT_STATUS' => ' disabled'));
         $this->_objTpl->parse('mediaEmptyDirectory');
     } elseif (empty($searchTerm)) {
         // not empty dir and not search results
         $this->_objTpl->setVariable(array('TXT_SELECT_ALL' => $_CORELANG['TXT_SELECT_ALL'], 'TXT_DESELECT_ALL' => $_CORELANG['TXT_DESELECT_ALL'], 'TXT_MEDIA_SELECT_ACTION' => $_ARRAYLANG['TXT_MEDIA_SELECT_ACTION'], 'TXT_MEDIA_CUT' => $_ARRAYLANG['TXT_MEDIA_CUT'], 'TXT_MEDIA_COPY' => $_ARRAYLANG['TXT_MEDIA_COPY'], 'TXT_MEDIA_DELETE' => $_ARRAYLANG['TXT_MEDIA_DELETE']));
         $this->_objTpl->parse('mediaSelectAction');
         $this->_objTpl->setVariable('MEDIA_ARCHIVE', $this->archive);
     }
     // paste media
     if (empty($searchTerm) && (isset($_SESSION['mediaCutFile']) || isset($_SESSION['mediaCopyFile']))) {
         $this->_objTpl->setVariable(array('MEDIDA_PASTE_ACTION' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=paste&amp;path=' . $this->webPath, 'TXT_MEDIA_PASTE' => $_ARRAYLANG['TXT_MEDIA_PASTE']));
         $this->_objTpl->parse('mediaActionPaste');
     }
     if (empty($searchTerm)) {
         //data we want to remember for handling the uploaded files
         $data = array('path' => $this->path, 'webPath' => $this->webPath);
         $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader();
         $uploader->setCallback('mediaCallbackJs');
         $uploader->setFinishedCallback(array(ASCMS_CORE_MODULE_PATH . '/Media/Controller/MediaLibrary.class.php', '\\Cx\\Core_modules\\Media\\Controller\\MediaLibrary', 'uploadFinished'));
         $uploader->setOptions(array('id' => 'media_browse_button', 'type' => 'button'));
         $uploader->setData($data);
         //end of uploader button handling
         $this->_objTpl->setVariable(array('MEDIA_UPLOADER_BUTTON' => $uploader->getXHtml($_ARRAYLANG['TXT_MEDIA_UPLOAD_FILES']), 'MEDIA_UPLOAD_FILES_ACTION' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=upload&amp;path=' . $this->webPath, 'TXT_MEDIA_UPLOAD_FILES' => $_ARRAYLANG['TXT_MEDIA_UPLOAD_FILES'], 'TXT_MEDIA_UPLOAD' => $_ARRAYLANG['TXT_MEDIA_UPLOAD'], 'TXT_MEDIA_FORCE_OVERWRITE' => $_ARRAYLANG['TXT_MEDIA_FORCE_OVERWRITE'], 'TXT_MEDIA_MAKE_SELECTION' => $_ARRAYLANG['TXT_MEDIA_MAKE_SELECTION'], 'TXT_MEDIA_SELECT_UPLOAD_FILE' => $_ARRAYLANG['TXT_MEDIA_SELECT_UPLOAD_FILE'], 'MEDIA_CREATE_DIR_ACTION' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=newDir&amp;path=' . $this->webPath, 'TXT_MEDIA_NEW_DIRECTORY' => $_ARRAYLANG['TXT_MEDIA_NEW_DIRECTORY'], 'TXT_MEDIA_NAME' => $_ARRAYLANG['TXT_MEDIA_NAME'], 'TXT_MEDIA_CREATE' => $_ARRAYLANG['TXT_MEDIA_CREATE']));
     } else {
         $this->_objTpl->hideBlock('media_archive_actions_block');
         $this->_objTpl->hideBlock('media_archive_newdir_block');
     }
     // parse variables
     $tmpHref = 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;path=' . $this->webPath . (!empty($searchTerm) ? '&amp;term=' . contrexx_raw2xhtml($searchTerm) : '');
     $tmpIcon = $this->_sortingIcons();
     $tmpClass = $this->_sortingClass();
     $this->_objTpl->setVariable(array('MEDIA_NAME_HREF' => $tmpHref . '&amp;sort=name&amp;sort_desc=' . ($this->sortBy == 'name' && !$this->sortDesc), 'MEDIA_SIZE_HREF' => $tmpHref . '&amp;sort=size&amp;sort_desc=' . ($this->sortBy == 'size' && !$this->sortDesc), 'MEDIA_TYPE_HREF' => $tmpHref . '&amp;sort=type&amp;sort_desc=' . ($this->sortBy == 'type' && !$this->sortDesc), 'MEDIA_DATE_HREF' => $tmpHref . '&amp;sort=date&amp;sort_desc=' . ($this->sortBy == 'date' && !$this->sortDesc), 'MEDIA_PERM_HREF' => $tmpHref . '&amp;sort=perm&amp;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'], 'TXT_MEDIA_FILE_FUNCTIONS' => $_ARRAYLANG['TXT_FUNCTIONS'], 'TXT_MEDIA_CHECK_NAME' => $_ARRAYLANG['TXT_MEDIA_CHECK_NAME'], 'TXT_MEDIA_CONFIRM_DELETE_2' => $_ARRAYLANG['TXT_MEDIA_CONFIRM_DELETE_2'], 'TXT_MEDIA_SEARCH' => $_CORELANG['TXT_SEARCH'], 'MEDIA_NAME_ICON' => isset($tmpIcon['name']) ? $tmpIcon['name'] : '', 'MEDIA_SIZE_ICON' => isset($tmpIcon['size']) ? $tmpIcon['size'] : '', 'MEDIA_TYPE_ICON' => isset($tmpIcon['type']) ? $tmpIcon['type'] : '', 'MEDIA_DATE_ICON' => isset($tmpIcon['date']) ? $tmpIcon['date'] : '', 'MEDIA_PERM_ICON' => isset($tmpIcon['perm']) ? $tmpIcon['perm'] : '', 'MEDIA_NAME_CLASS' => isset($tmpClass['name']) ? $tmpIcon['name'] : '', 'MEDIA_SIZE_CLASS' => isset($tmpClass['size']) ? $tmpIcon['size'] : '', 'MEDIA_TYPE_CLASS' => isset($tmpClass['type']) ? $tmpIcon['type'] : '', 'MEDIA_DATE_CLASS' => isset($tmpClass['date']) ? $tmpIcon['date'] : '', 'MEDIA_PERM_CLASS' => isset($tmpClass['perm']) ? $tmpIcon['perm'] : '', 'MEDIA_ARCHIVE_NAME' => $this->archive, 'MEDIA_ARCHIVE_PATH' => $this->webPath, 'MEDIA_SEARCH_TERM' => contrexx_raw2xhtml(rawurldecode($searchTerm)), 'CSRF' => \Cx\Core\Csrf\Controller\Csrf::param(), 'MEDIA_DO_ACTION_PATH' => rawurlencode($this->webPath), 'MEDIA_JAVA_SCRIPT_PREVIEW' => $this->_getJavaScriptCodePreview()));
 }