Esempio n. 1
0
	/**
	 * Load the values from either the page request or the session data.
	 *
	 * @param PageRequest $request
	 */
	public function load(PageRequest $request){
		// First, load everything from the session.
		$this->loadSession();

		$a = array();
		$s = array();
		$p = array();

		// Check the sort keys?
		if($this->hassort){
			if($request->getParameter('sortkey')){
				$this->setSortKey($request->getParameter('sortkey'));
				$s['sortkey'] = $this->_sortkey;
			}
			if($request->getParameter('sortdir')){
				$this->setSortDirection($request->getParameter('sortdir'));
				$s['sortdir'] = $this->_sortdir;
			}
		}

		// Did the user change a filter?
		// If a filter was changed, reset back to page 1!
		if($request->getParameter('filter')){
			$filters = $request->getParameter('filter');

			foreach($filters as $f => $v){
				if(!isset($this->_elementindexes['filter[' . $f . ']'])) continue;
				/** @var $el FormElement */
				$el = $this->_elementindexes['filter[' . $f . ']'];
				$el->setValue($v);

				// Remember this for the session data.
				$a[$f] = $v;
				$this->setPage(1);
				$p['page'] = 1;
			}
		}
		// How 'bout the pagination?
		elseif($this->haspagination){
			if($request->getParameter('page')){
				$this->setPage($request->getParameter('page'));
				$p['page'] = $this->_currentpage;
			}
			elseif($request->getParameter('limit')){
				$this->setPage(1);
				$p['page'] = 1;
				
				$this->setLimit($request->getParameter('limit'));
				$p['limit'] = $this->_limit;
			}
			// Don't change the filter sets, those have been cached and are fine as-is.
		}
		else{
			// No pagination or filters were modified... don't do anything.
		}


		if(sizeof($a)){
			\Core\Session::Set('filters/' . $this->_name, $a);
		}
		if(sizeof($s)){
			\Core\Session::Set('filtersort/' . $this->_name, $s);
		}
		if(sizeof($p)){
			\Core\Session::Set('filterpage/' . $this->_name, $p);
		}
	}
 private function _setupFileBrowser(View $view, PageRequest $request, $type)
 {
     $view->templatename = 'pages/tinymce/browser-icons.tpl';
     $view->mastertemplate = 'blank.tpl';
     $view->record = false;
     $accesspermission = 'p:/tinymce/filebrowser/access';
     $uploadpermission = 'p:/tinymce/filebrowser/upload';
     $sandboxconfig = '/tinymce/filebrowser/sandbox-user-uploads';
     if ($type == 'image') {
         $accept = 'image/*';
     } else {
         $accept = '*';
     }
     if (!\Core\user()->checkAccess($accesspermission)) {
         return View::ERROR_ACCESSDENIED;
     }
     // Get a listing of files in the appropriate directory.
     if (ConfigHandler::Get($sandboxconfig)) {
         $basedirname = 'public/tinymce/' . \Core\user()->get('id') . '/';
     } else {
         $basedirname = 'public/tinymce/';
     }
     if ($request->getParameter('dir')) {
         $dirname = $basedirname . str_replace('..', '', $request->getParameter('dir'));
     } else {
         $dirname = $basedirname;
     }
     // This will create a navigatable tree of directory listings for the user.
     $tree = explode('/', substr($dirname, strlen($basedirname)));
     $treestack = '';
     foreach ($tree as $k => $v) {
         if (!trim($v)) {
             unset($tree[$k]);
         } else {
             $treestack .= '/' . $v;
             $tree[$k] = array('name' => $v, 'stack' => $treestack);
         }
     }
     $dir = \Core\Filestore\Factory::Directory($dirname);
     // Allow automatic creation of the root directory.
     if ($dirname == $basedirname && !$dir->exists()) {
         $dir->mkdir();
     }
     if (!$dir->exists()) {
         return View::ERROR_NOTFOUND;
     }
     $dirlen = strlen($dir->getPath());
     $directories = array();
     $files = array();
     foreach ($dir->ls() as $file) {
         if ($file instanceof \Core\Filestore\Directory) {
             // Give me a count of children in that directory.  I need to do the logic custom here because I only want directories and imgaes.
             $count = 0;
             foreach ($file->ls() as $subfile) {
                 if ($file instanceof \Core\Filestore\Directory) {
                     $count++;
                 } elseif ($file instanceof \Core\Filestore\File) {
                     if ($type == 'image' && $file->isImage() || $type == 'file') {
                         $count++;
                     }
                 }
             }
             $directories[$file->getBasename()] = array('object' => $file, 'name' => $file->getBasename(), 'browsename' => substr($file->getPath(), $dirlen), 'children' => $count);
         } elseif ($file instanceof \Core\Filestore\File) {
             // I only want images
             if ($type == 'image' && !$file->isImage()) {
                 continue;
             }
             $files[$file->getBaseFilename()] = array('object' => $file, 'name' => $file->getBaseFilename(), 'selectname' => $file->getURL());
         }
     }
     // Sorting would be nice!
     ksort($directories);
     ksort($files);
     // Size presets
     $size = \Core\user()->get('/tinymce/filebrowser/size');
     if (!$size) {
         $size = 'lg';
     }
     switch ($size) {
         case 'sm':
             $sizepx = 16;
             break;
         case 'med':
             $sizepx = 32;
             break;
         case 'lg':
             $sizepx = 64;
             break;
         case 'xl':
             $sizepx = 128;
             break;
         default:
             $size = 'lg';
             $sizepx = 64;
     }
     // Only certain people are allowed the rights to upload here.
     if (\Core\user()->checkAccess($uploadpermission)) {
         $uploadform = new Form();
         $uploadform->set('action', \Core\resolve_link('/tinymce/' . $type . '/upload'));
         $uploadform->addElement('multifile', array('basedir' => $dirname, 'title' => 'Upload Files', 'name' => 'files', 'accept' => $accept));
         //$uploadform->addElement('submit', array('value' => 'Bulk Upload'));
     } else {
         $uploadform = false;
     }
     // Give me some useful tips to show the user.
     $tips = array('You can drag and drop files from your local machine to upload them!', 'You can double click on a directory to browse that directory.', 'You can single click on a file or directory to view more information about that file.', 'You can use the direction arrows on your keyboard to navigate between files!', 'Pressing ESCAPE will deselect any selected files.', 'You are free to rename or delete files at will, but be aware, you may delete a file you need!');
     $view->assign('directories', array_values($directories));
     $view->assign('files', array_values($files));
     $view->assign('size', $size);
     $view->assign('sizepx', $sizepx);
     $view->assign('location_tree', $tree);
     $view->assign('location', $treestack);
     $view->assign('tip', $tips[rand(0, sizeof($tips) - 1)]);
     $view->assign('uploadform', $uploadform);
     return View::ERROR_NOERROR;
 }