nyroFwk  0.2
nyro/module/nyroBrowser/controller.class.php
Go to the documentation of this file.
1 <?php
3 
4  protected $myCfg;
5  protected $dir;
6  protected $type;
7  protected $config;
8  protected $uri;
9 
10  protected function prepare() {
11  $htVars = http_vars::getInstance();
12  $this->type = $htVars->post('type', $htVars->get('type'));
13  $this->config = $htVars->post('config', $htVars->get('config', 'default'));
14 
15  $this->myCfg = $this->cfg->default;
16  if ($this->config != 'default' && is_array($this->cfg->get($this->config)))
17  factory::mergeCfg($this->myCfg, $this->cfg->get($this->config));
18 
19  $this->dir = $this->myCfg['dir'];
20  if ($this->myCfg['subdir'])
21  $this->dir.= DS.$this->myCfg['subdir'];
22 
23  $this->dir.= DS.$this->type;
24 
25  $resp = response::getInstance();
26  /* @var $resp response_http_html */
27  $resp->setLayout($this->myCfg['layout']);
28  $resp->setTitle($this->myCfg['title']);
29  $resp->initIncFiles(false);
30  foreach($this->myCfg['incFiles'] as $ic)
31  $resp->add($ic);
32 
33  $this->uri = request::uriDef(array('module')).'?'.session::getInstance()->getSessIdForce().'='.urlencode(session_id()).'&type='.$this->type.'&config='.$this->config.'&';
34  }
35 
36  protected function execIndex(array $prm = array()) {
37  $this->prepare();
38 
39  $pattern = FILESROOT.$this->dir.DS.'*';
40  $search = http_vars::getInstance()->get('search');
41  if ($search) {
42  $pattern.= strtolower($search).'*';
43  $this->uri.= 'search='.$search.'&';
44  }
45 
46  $delete = http_vars::getInstance()->get('delete');
47  if ($delete) {
48  $file = FILESROOT.urldecode($delete);
49  if (file::exists($file)) {
50  file::delete($file);
51  file::multipleDelete(substr($file, 0, -strlen(file::getExt($file))-1).'_*');
52  response::getInstance()->redirect($this->uri);
53  }
54  }
55 
56  $form = $this->getForm();
57 
58  if (request::isPost()) {
59  $form->refill();
60  if ($form->isValid())
61  response::getInstance()->sendText('ok');
62  }
63 
64  $files = array();
65  foreach(file::search($pattern) as $f) {
66  if (strpos($f, 'nyroBrowserThumb') === false) {
67  $name = basename($f);
68  if ($this->type == 'image' && strlen($name) > 15)
69  $name = substr($name, 0, 15).'...'.file::getExt($f);
70  $files[] = array(
71  $f,
72  request::uploadedUri(str_replace(FILESROOT, '', $f), $this->myCfg['uploadedUri']),
73  $name,
74  file::humanSize($f),
75  utils::formatDate(filemtime($f)),
76  $this->uri.'delete='.urlencode(str_replace(FILESROOT, '', $f)).'&'
77  );
78  }
79  }
80 
81  $this->setViewVars(array(
82  'uri'=>$this->uri,
83  'form'=>$form,
84  'config'=>$this->config,
85  'type'=>$this->type,
86  'files'=>$files,
87  'searchButton'=>$this->myCfg['search'],
88  'search'=>$search,
89  'imgHelper'=>$this->myCfg['imgHelper'],
90  'filesTitle'=>$this->myCfg['filesTitle'],
91  'noFiles'=>$this->myCfg['noFiles'],
92  'name'=>$this->myCfg['name'],
93  'size'=>$this->myCfg['size'],
94  'date'=>$this->myCfg['date'],
95  'delete'=>$this->myCfg['delete'],
96  ));
97  }
98 
99  protected function getForm() {
100  $form = factory::get('form', array_merge(array(
101  'sectionName'=>$this->myCfg['formName'],
102  'action'=>$this->uri
103  ), $this->myCfg['formCfg']));
104 
105  $form->add('file', array(
106  'name'=>'file',
107  'subdir'=>$this->dir,
108  'helper'=>$this->myCfg['helper'][$this->type]['name'],
109  'helperPrm'=>$this->myCfg['helper'][$this->type]['prm'],
110  ));
111  $form->get('file')->plupload(array_merge($this->myCfg['plupload'][$this->type], array(
112  'multipart_params'=>array(
113  'type'=>$this->type,
114  'config'=>$this->config,
115  ),
116  'onAllComplete'=>'function() {window.location.href = "'.$this->uri.'";}'
117  )));
118 
119  return $form;
120  }
121 
122 }
static formatDate($date, $type='date', $len='short2', $htmlOut=true)
if(!defined('NYROROOT')) define('NYROROOT' ROOT DS
Definition: start.inc.php:56
static exists($file)
Definition: file.class.php:97
static humanSize($file, $sizeGiven=false)
Definition: file.class.php:339
static getInstance(array $cfg=array())
static getExt($file)
Definition: file.class.php:400
static getInstance()
static uploadedUri($file, array $prm=array())
static mergeCfg(array &$prm, array $cfg)
static delete($file)
Definition: file.class.php:355
static multipleDelete($pattern, $matchPattern=null)
Definition: file.class.php:386
static uriDef(array $prm=array(), array $use=array('lang', 'module', 'action', 'param', 'out'))
static isPost()
setViewVars(array $values)
$f
Definition: list.php:6
static getInstance()
Definition: vars.class.php:29
static search($pattern, $matchPattern=null)
Definition: file.class.php:457
static get($className, array $cfg=array())
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13