XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
file.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
7 class fileAdminController extends file
8 {
13  function init()
14  {
15  }
16 
24  {
25  // Get a full list of attachments
26  $args = new stdClass();
27  $args->module_srl = $module_srl;
28  $columnList = array('file_srl', 'uploaded_filename');
29  $output = executeQueryArray('file.getModuleFiles',$args, $columnList);
30  if(!$output) return $output;
31  $files = $output->data;
32  // Remove from the DB
33  $args->module_srl = $module_srl;
34  $output = executeQuery('file.deleteModuleFiles', $args);
35  if(!$output->toBool()) return $output;
36  // Remove the file
37  FileHandler::removeDir( sprintf("./files/attach/images/%s/", $module_srl) ) ;
38  FileHandler::removeDir( sprintf("./files/attach/binaries/%s/", $module_srl) );
39  // Remove the file list obtained from the DB
40  $path = array();
41  $cnt = count($files);
42  for($i=0;$i<$cnt;$i++)
43  {
44  $uploaded_filename = $files[$i]->uploaded_filename;
45  FileHandler::removeFile($uploaded_filename);
46 
47  $path_info = pathinfo($uploaded_filename);
48  if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname'];
49  }
50  // Remove a file directory of the document
51  for($i=0;$i<count($path);$i++) FileHandler::removeBlankDir($path[$i]);
52 
53  return $output;
54  }
55 
62  {
63  // An error appears if no document is selected
64  $cart = Context::get('cart');
65  if(!$cart) return $this->stop('msg_file_cart_is_null');
66  if(!is_array($cart)) $file_srl_list= explode('|@|', $cart);
67  else $file_srl_list = $cart;
68  $file_count = count($file_srl_list);
69  if(!$file_count) return $this->stop('msg_file_cart_is_null');
70 
71  $oFileController = getController('file');
72  // Delete the post
73  for($i=0;$i<$file_count;$i++)
74  {
75  $file_srl = trim($file_srl_list[$i]);
76  if(!$file_srl) continue;
77 
78  $oFileController->deleteFile($file_srl);
79  }
80 
81  $this->setMessage( sprintf(Context::getLang('msg_checked_file_is_deleted'), $file_count) );
82 
83  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispFileAdminList');
84  $this->setRedirectUrl($returnUrl);
85  }
86 
93  {
94  // Get configurations (using module model object)
95  $config = new stdClass();
96  $config->allowed_filesize = Context::get('allowed_filesize');
97  $config->allowed_attach_size = Context::get('allowed_attach_size');
98  $config->allowed_filetypes = str_replace(' ', '', Context::get('allowed_filetypes'));
99  $config->allow_outlink = Context::get('allow_outlink');
100  $config->allow_outlink_format = Context::get('allow_outlink_format');
101  $config->allow_outlink_site = Context::get('allow_outlink_site');
102  // Create module Controller object
103  $oModuleController = getController('module');
104  $output = $oModuleController->insertModuleConfig('file',$config);
105 
106  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispFileAdminConfig');
107  return $this->setRedirectUrl($returnUrl, $output);
108  }
109 
116  {
117  // Get variables
118  $module_srl = Context::get('target_module_srl');
119  // In order to configure multiple modules at once
120  if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl);
121  else $module_srl = array($module_srl);
122 
123  $download_grant = Context::get('download_grant');
124 
125  $file_config = new stdClass;
126  $file_config->allow_outlink = Context::get('allow_outlink');
127  $file_config->allow_outlink_format = Context::get('allow_outlink_format');
128  $file_config->allow_outlink_site = Context::get('allow_outlink_site');
129  $file_config->allowed_filesize = Context::get('allowed_filesize');
130  $file_config->allowed_attach_size = Context::get('allowed_attach_size');
131  $file_config->allowed_filetypes = str_replace(' ', '', Context::get('allowed_filetypes'));
132 
133  if(!is_array($download_grant)) $file_config->download_grant = explode('|@|',$download_grant);
134  else $file_config->download_grant = $download_grant;
135 
136  //관리자가 허용한 첨부파일의 사이즈가 php.ini의 값보다 큰지 확인하기 - by ovclas
137  $userFileAllowSize = FileHandler::returnbytes($file_config->allowed_filesize.'M');
138  $userAttachAllowSize = FileHandler::returnbytes($file_config->allowed_attach_size.'M');
139  $iniPostMaxSize = FileHandler::returnbytes(ini_get('post_max_size'));
140  $iniUploadMaxSize = FileHandler::returnbytes(ini_get('upload_max_filesize'));
141  $iniMinSzie = min($iniPostMaxSize, $iniUploadMaxSize);
142 
143  if($userFileAllowSize > $iniMinSzie || $userAttachAllowSize > $iniMinSzie)
144  return new BaseObject(-1, 'input size over than config in php.ini');
145 
146  $oModuleController = getController('module');
147  for($i=0;$i<count($module_srl);$i++)
148  {
149  $srl = trim($module_srl[$i]);
150  if(!$srl) continue;
151  $oModuleController->insertModulePartConfig('file',$srl,$file_config);
152  }
153 
154  $this->setError(-1);
155  $this->setMessage('success_updated', 'info');
156 
157  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispBoardAdminContent');
158  $this->setRedirectUrl($returnUrl);
159  }
160 
167  {
168  $file_srl = (int)Context::get('file_srl');
169  //$fileSrlList = array(500, 502);
170 
171  $oFileModel = getModel('file');
172  $output = $oFileModel->getFile($file_srl);
173  //$output = $oFileModel->getFile($fileSrlList);
174 
175  if($output->file_srl)
176  {
177  if($_SESSION['file_management'][$output->file_srl]) unset($_SESSION['file_management'][$output->file_srl]);
178  else $_SESSION['file_management'][$output->file_srl] = true;
179  }
180  }
181 }
182 /* End of file file.admin.controller.php */
183 /* Location: ./modules/file/file.admin.controller.php */
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
removeFile($filename)
$output
Definition: ko.install.php:193
getNotEncodedUrl()
Definition: func.inc.php:316
$module_srl
integer value to represent a run-time instance of Module (XE Module)
setError($error=0)
$args
Definition: ko.install.php:185
setRedirectUrl($url= './', $output=NULL)
getLang($code)
getModel($module_name)
Definition: func.inc.php:145
executeQueryArray($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:219
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
$oModuleController
Definition: ko.install.php:287