Esempio n. 1
0
 private function listContent()
 {
     $listSubFolder = $this->listSubFolder;
     $listFiles = $this->listFiles;
     $folderId = $this->request->arg[1];
     $page = empty($this->request->arg[2]) ? 1 : $this->request->arg[2];
     $limitNum = Config::get('default_file_pager');
     $startId = ($page - 1) * $limitNum;
     $this->data['limitNum'] = $limitNum;
     $this->data['page'] = $page;
     import('dao.Folder');
     $folder = new Folder();
     $myFolder = $folder->getFolder($folderId);
     if (empty($myFolder)) {
         goToUrl('/pageNotFound');
     }
     $this->data['currentFolderId'] = $myFolder['fd_id'];
     if ($listSubFolder) {
         $options = array('limit' => $limitNum, 'start' => $startId);
         $subFolders = $folder->getSubFolder($myFolder['fd_id'], $options);
         foreach ($subFolders as $key => $subFolder) {
             $defaultCoverThumb = Config::get('default_cover_thumbnail');
             $defaultCoverThumb = empty($defaultCoverThumb) ? '/images/default_cover_thumbnail.jpg' : $defaultCoverThumb;
             $folderCover = $folder->getFolderCover($subFolder['fd_id']);
             $coverThumb = imageCache::cacheImage($folderCover, 160, 120);
             $subFolder['thumbnail'] = $coverThumb ? $coverThumb : $defaultCoverThumb;
             $subFolder['filesNum'] = count($folder->getFilesInFolder($subFolder['fd_id'], array("where" => "and image_type>0")));
             $subFolder['subFoldersNum'] = count($folder->getSubFolder($subFolder['fd_id']));
             $subFolders[$key] = $subFolder;
         }
         $this->data['folders'] = $subFolders;
         $this->data['subFolderTotal'] = $folder->getSubFolderTotal($folderId);
         if ($listFiles && count($this->data['subFolderTotal']) > $limitNum) {
             $this->data['subFolderPager'] = 'more';
         } else {
             $this->data['subFolderPager'] = 'full';
         }
     }
     if ($listFiles) {
         $options = array("where" => "and image_type>0", "limit" => $limitNum, 'start' => $startId);
         $myFiles = $folder->getFilesInFolder($folderId, $options);
         foreach ($myFiles as $key => $myFile) {
             $defaultThumb = Config::get('default_thumbnail');
             $defaultThumb = empty($defaultThumb) ? '/images/default_thumbnail.jpg' : $defaultThumb;
             $myThumb = imageCache::cacheImage($myFile['path'], 160, 120);
             $myFile['thumbnail'] = $myThumb ? $myThumb : $defaultThumb;
             $myFiles[$key] = $myFile;
         }
         //ZDebug::my_print($myFiles, 'files');
         $this->data['files'] = $myFiles;
         $this->data['filesTotal'] = $folder->getFilesInFolderTotal($folderId);
         if ($listSubFolder && count($this->data['filesTotal']) > $limitNum) {
             $this->data['filesPager'] = 'more';
         } else {
             $this->data['filesPager'] = 'full';
         }
     }
     $this->data['currentFolderName'] = $myFolder['name'];
     $this->data['nav'] = $this->genNav($myFolder, $folder);
 }
Esempio n. 2
0
 public function blockHeaderData()
 {
     $headerData['site_logo'] = Config::get('site_logo');
     $menuLinks = array();
     import('dao.Folder');
     $folder = new Folder();
     $folders = $folder->getSubFolder(0);
     foreach ($folders as $folderItem) {
         $menuLinks[] = array('name' => $folderItem['name'], 'url' => '/list/' . $folderItem['fd_id']);
     }
     $headerData['menuLinks'] = $menuLinks;
     return $headerData;
 }
Esempio n. 3
0
 public static function syncFolders($folderToSync)
 {
     $debug = self::$debug;
     $mode = self::$mode;
     import('dao.Folder');
     $folder = new Folder();
     import('dao.File');
     $file = new File();
     $folderFullName = $folderToSync['path'];
     $folderId = $folderToSync['fd_id'];
     // If folder is locked, ignore. Unless set mode greater than 0.
     if ($folderToSync['locked'] && $mode == 0) {
         if ($debug) {
             ZDebug::my_echo('Ignore locked folder: ' . $folderFullName . '(' . $folderId . ')');
         }
         return TRUE;
     }
     // Step 1: If folder is not physically exist, set to deleted in DB.
     if (!is_dir($folderFullName)) {
         $folder->deleteFolder($folderId);
         if ($debug) {
             ZDebug::my_echo('Delete folder in DB: ' . $folderFullName . '(' . $folderId . ')');
         }
         return TRUE;
     }
     // Step 2: Get the result set of files under this folder
     $filesInFolder = $folder->getFilesInFolder($folderId);
     $fileNameArr = array();
     foreach ($filesInFolder as $theFile) {
         // Step 3: If a file is not physically exist, delete it in table files.
         if (!file_exists($theFile['path'])) {
             $file->deleteFile($theFile['fid']);
             if ($debug) {
                 ZDebug::my_echo('Delete file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')');
             }
         } elseif ($theFile['last_modified'] != my_filemtime($theFile['path'])) {
             $theFile['last_modified'] = my_filemtime($theFile['path']);
             $file->saveFile($theFile);
             if ($debug) {
                 ZDebug::my_echo('Update file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')');
             }
         } elseif ($mode > 1) {
             $file->saveFile($theFile);
             if ($debug) {
                 ZDebug::my_echo('Update file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')');
             }
         } else {
         }
         $fileNameArr[] = $theFile['name'];
     }
     // Step 5: Get result set of sub-folders under this folder
     $subFoldera = $folder->getSubFolder($folderId);
     $folderNameArr = array();
     foreach ($subFoldera as $theFolder) {
         // Step 6: If a folder is not physically exist, set deleted flag in table folders.
         if (!file_exists($theFolder['path'])) {
             $folder->deleteFolder($theFolder['fd_id']);
             if ($debug) {
                 ZDebug::my_echo('Delete folder in DB: ' . $theFolder['path'] . '(' . $theFolder['fd_id'] . ')');
             }
         } elseif ($theFolder['last_modified'] != my_filemtime($theFolder['path'])) {
             $theFolder['last_modified'] = my_filemtime($theFolder['path']);
             $folder->saveFolder($theFolder);
             if ($debug) {
                 ZDebug::my_echo('Update folder in DB: ' . $theFolder['path'] . '(' . $theFolder['fd_id'] . ')');
             }
             self::syncFolders($theFolder);
         } else {
             self::syncFolders($theFolder);
         }
         $folderNameArr[] = $theFolder['name'];
     }
     $hdl = opendir($folderFullName);
     while ($item = readdir($hdl)) {
         $itemFullName = $folderFullName . DIRECTORY_SEPARATOR . $item;
         // Step 8: If physical file is not in DB file result set, then add a file
         if ($item != "." && $item != ".." && is_file($itemFullName) && !in_array($item, $fileNameArr)) {
             $file->saveFile(array('path' => $itemFullName, 'fd_id' => $folderId));
             if ($debug > 1) {
                 ZDebug::my_echo('Adding new file in DB: ' . $itemFullName);
             }
         }
         // Step 9: if physical folder is not in DB folder result set, then add a folder
         if ($item != "." && $item != ".." && is_dir($itemFullName) && !in_array($item, $folderNameArr)) {
             self::addFolder($itemFullName, $folderId);
         }
     }
     closedir($hdl);
 }