00001 <?php
00002 class module_nyroBrowser_controller extends module_abstract {
00003
00004 protected $myCfg;
00005 protected $dir;
00006 protected $type;
00007 protected $config;
00008 protected $uri;
00009
00010 protected function prepare() {
00011 $htVars = http_vars::getInstance();
00012 $this->type = $htVars->post('type', $htVars->get('type'));
00013 $this->config = $htVars->post('config', $htVars->get('config', 'default'));
00014
00015 $this->myCfg = $this->cfg->default;
00016 if ($this->config != 'default' && is_array($this->cfg->get($this->config)))
00017 factory::mergeCfg($this->myCfg, $this->cfg->get($this->config));
00018
00019 $this->dir = $this->myCfg['dir'];
00020 if ($this->myCfg['subdir'])
00021 $this->dir.= DS.$this->myCfg['subdir'];
00022
00023 $this->dir.= DS.$this->type;
00024
00025 $resp = response::getInstance();
00026
00027 $resp->setLayout($this->myCfg['layout']);
00028 $resp->setTitle($this->myCfg['title']);
00029 $resp->initIncFiles(false);
00030 foreach($this->myCfg['incFiles'] as $ic)
00031 $resp->add($ic);
00032
00033 $this->uri = request::uriDef(array('module')).'?'.session::getInstance()->getSessIdForce().'='.urlencode(session_id()).'&type='.$this->type.'&config='.$this->config.'&';
00034 }
00035
00036 protected function execIndex(array $prm = array()) {
00037 $this->prepare();
00038
00039 $pattern = FILESROOT.$this->dir.DS.'*';
00040 $search = http_vars::getInstance()->get('search');
00041 if ($search) {
00042 $pattern.= strtolower($search).'*';
00043 $this->uri.= 'search='.$search.'&';
00044 }
00045
00046 $delete = http_vars::getInstance()->get('delete');
00047 if ($delete) {
00048 $file = FILESROOT.urldecode($delete);
00049 if (file::exists($file)) {
00050 file::delete($file);
00051 file::multipleDelete(substr($file, 0, -strlen(file::getExt($file))-1).'_*');
00052 response::getInstance()->redirect($this->uri);
00053 }
00054 }
00055
00056 $form = $this->getForm();
00057
00058 if (request::isPost()) {
00059 $form->refill();
00060 if ($form->isValid())
00061 response::getInstance()->sendText('ok');
00062 }
00063
00064 $files = array();
00065 foreach(file::search($pattern) as $f) {
00066 if (strpos($f, 'nyroBrowserThumb') === false) {
00067 $name = basename($f);
00068 if ($this->type == 'image' && strlen($name) > 15)
00069 $name = substr($name, 0, 15).'...'.file::getExt($f);
00070 $files[] = array(
00071 $f,
00072 request::uploadedUri(str_replace(FILESROOT, '', $f), $this->myCfg['uploadedUri']),
00073 $name,
00074 file::humanSize($f),
00075 utils::formatDate(filemtime($f)),
00076 $this->uri.'delete='.urlencode(str_replace(FILESROOT, '', $f)).'&'
00077 );
00078 }
00079 }
00080
00081 $this->setViewVars(array(
00082 'uri'=>$this->uri,
00083 'form'=>$form,
00084 'config'=>$this->config,
00085 'type'=>$this->type,
00086 'files'=>$files,
00087 'searchButton'=>$this->myCfg['search'],
00088 'search'=>$search,
00089 'imgHelper'=>$this->myCfg['imgHelper'],
00090 'filesTitle'=>$this->myCfg['filesTitle'],
00091 'noFiles'=>$this->myCfg['noFiles'],
00092 'name'=>$this->myCfg['name'],
00093 'size'=>$this->myCfg['size'],
00094 'date'=>$this->myCfg['date'],
00095 'delete'=>$this->myCfg['delete'],
00096 ));
00097 }
00098
00099 protected function getForm() {
00100 $form = factory::get('form', array_merge(array(
00101 'sectionName'=>$this->myCfg['formName'],
00102 'action'=>$this->uri
00103 ), $this->myCfg['formCfg']));
00104
00105 $form->add('file', array(
00106 'name'=>'file',
00107 'subdir'=>$this->dir,
00108 'helper'=>$this->myCfg['helper'][$this->type]['name'],
00109 'helperPrm'=>$this->myCfg['helper'][$this->type]['prm'],
00110 'uploadify'=>array('scriptData'=>array(
00111 'type'=>$this->type,
00112 'config'=>$this->config,
00113 )),
00114 ));
00115 $form->get('file')->uploadify(array_merge($this->myCfg['uploadify'][$this->type], array(
00116 'script'=>$this->uri,
00117 'onAllComplete'=>'function() {window.location.href = "'.$this->uri.'";}'
00118 )));
00119
00120 return $form;
00121 }
00122
00123 }