function displayFolderList($folderId = 0, $folderPath = '', $page = 1, $sortBy = 'name', $sortDir = 'asc', $view = 'default', $highlight = array(), $history = true, &$response, $noError = false) { global $EDITOR, $DIALOG, $WPRO_SESS; // initial var check... if (!$response) { $response = $DIALOG->createAjaxResponse(); } if (!is_string($folderId) && !is_int($folderId) || !is_string($folderPath) || !is_array($highlight)) { $response->addAlert('Datatype error.'); $response->addScriptCall("FB.onFolderNotFound", ""); return $response; } $page = intval($page); if ($page == 0) { $page = 1; } $pageLength = 100; if ($arr = $this->getFolder($folderId, $folderPath, $response, $noError)) { $directory = $arr['directory']; $URL = $arr['URL']; $dir = $arr['dir']; if ($arr['changed']) { $highlight = array(); } $tpl = new wproTemplate(); // if images, should we display thumbnails if ($EDITOR->thumbnails && $dir->type == 'image') { if ($view == 'default') { $view = $EDITOR->defaultImageView; } $thumbnails = $view == 'thumbnails' ? true : false; if ($thumbnails) { $params['sortBy'] = 'name'; $params['sortDir'] = 'asc'; } } else { $thumbnails = false; } // get sort by and sort direction // get and validate sorting /*if (isset ($params['sortBy'])) { $sortBy = $params['sortBy']; } else { $sortBy = 'name'; }*/ if ($sortBy != 'name' && $sortBy != 'type' && $sortBy != 'modified' && $sortBy != 'size') { $sortBy = 'name'; } /*if (isset ($params['sortDir'])) { $sortDir = $params['sortDir']; } else { $sortDir = 'asc'; }*/ if ($sortDir != 'asc' && $sortDir != 'desc') { $sortDir = 'asc'; } $folderSortBy = 'name'; if ($sortBy != 'name') { $folderSortDir = 'asc'; } else { $folderSortDir = $sortDir; } $tpl->assign('sortBy', $sortBy); $tpl->assign('sortDir', $sortDir); //if (isset($params['doHistory'])) { //$DIALOG->template->assign('doHistory', false); //} else { //$DIALOG->template->assign('doHistory', true); //} // build a standard URL base to use with everything. $urlBase = $this->getURLBase($dir->id, $folderPath); // display the file list // what types of files to display? $fileTypes = array(); switch ($dir->type) { case 'image': $fileTypes = $EDITOR->allowedImageExtensions; break; case 'media': $fileTypes = $EDITOR->allowedMediaExtensions; break; case 'document': default: $fileTypes = $EDITOR->allowedDocExtensions; break; } $fs = new wproFilesystem(); if ($dir->type == 'image') { $getDimensions = true; } else { $getDimensions = false; } // get the list of folders and files $files = $fs->getFilesInDir($directory, $sortBy, $sortDir, $fileTypes, $dir->filters, $getDimensions); // if images then we need to build the thumbnails! if ($thumbnails && count($files)) { if (!$this->buildThumbnails($directory, $URL, $files, $urlBase)) { $thumbnails = false; } } // build folders afterwards so that thumbnail folder is included. $folders = $fs->getFoldersInDir($directory, $folderSortBy, $folderSortDir, $dir->filters); $total = count($files) + count($folders); $numPages = ceil($total / $pageLength); // check for selected files and adjust current page if there is only one file selected. if (count($highlight) && $numPages > 1) { // OK, flip through the pages until we find the file. $j = 0; $found = false; $num = count($folders); for ($i = 0; $i < $num; $i++) { if (in_array($folders[$i]['name'], $highlight)) { $j = $i; $found = true; break; } } if (!$found) { $num = count($files); for ($i = 0; $i < $num; $i++) { if (in_array($files[$i]['name'], $highlight)) { $j = $i; break; } } } $page = ceil($j / $pageLength); if ($page == 0) { $page = 1; } } // sanitize current page $page = intval($page); while ($page > $numPages) { $page--; } $start = $page * $pageLength - $pageLength; $end = $start + $pageLength; if ($end > $total) { $end = $total; } $tpl->assign('pageStart', $start); // no at page start $tpl->assign('pageEnd', $end); // no at page end $tpl->assign('pageCurrent', $page); // current page $tpl->assign('pageNumPages', $numPages); // number of pages $tpl->assign('pageLength', $pageLength); // length of each page $tpl->assign('pageTotal', $total); // total no of files $tpl->assign('dir', $dir); $tpl->assign('thumbnails', $thumbnails); $tpl->assign('folders', $folders); $tpl->assign('files', $files); $tpl->assign('folderID', $dir->id); $tpl->assign('folderPath', $folderPath); $tpl->assign('folderURL', $URL); $tpl->assign('sortBy', $sortBy); $tpl->assign('sortDir', $sortDir); $tpl->assign('highlight', $highlight); $tpl->assign('doHistory', false); /* generic assigns */ /*$tpl->assignByRef('EDITOR', $EDITOR); $tpl->assignByRef('langEngine', $EDITOR->langEngine); $tpl->bulkAssign(array( 'themeURL' => $EDITOR->themeFolderURL.$EDITOR->theme.'/', 'editorURL' => $EDITOR->editorURL, 'langURL' => $EDITOR->langFolderURL.$DIALOG->langEngine->actualLang.'/', ));*/ $DIALOG->assignCommonVarsToTemplate($tpl); /* end */ $html = $tpl->fetch(WPRO_DIR . 'core/plugins/wproCore_fileBrowser/tpl/files.tpl.php'); //$response->addAlert($html); // nonce $nonce = md5(uniqid(rand(), true)); $response->addScriptCall("FB.setNonce", $nonce); $WPRO_SESS->addNonce($nonce, time() + 3600); $response->addAssign("folderFrame", "innerHTML", $html); $response->addScriptCall("FB.onLoadFolder", $history); } else { $response->addScriptCall("FB.onFolderNotFound", ""); } return $response; }