XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
integration_search.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 {
15  function init()
16  {
17  }
18 
25  {
26  // Get configurations (using module model object)
27  $oModuleModel = getModel('module');
28  $config = $oModuleModel->getModuleConfig('integration_search');
29 
30  $args = new stdClass;
31  $args->skin = Context::get('skin');
32  $args->target = Context::get('target');
33  $args->target_module_srl = Context::get('target_module_srl');
34  if(!$args->target_module_srl) $args->target_module_srl = '';
35  $args->skin_vars = $config->skin_vars;
36 
38  $output = $oModuleController->insertModuleConfig('integration_search',$args);
39 
40  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispIntegration_searchAdminContent');
41  return $this->setRedirectUrl($returnUrl, $output);
42  }
43 
50  {
51  // Get configurations (using module model object)
52  $oModuleModel = getModel('module');
53  $config = $oModuleModel->getModuleConfig('integration_search');
54 
55  $args = new stdClass;
56  $args->skin = $config->skin;
57  $args->target_module_srl = $config->target_module_srl;
58  // Get skin information (to check extra_vars)
59  $skin_info = $oModuleModel->loadSkinInfo($this->module_path, $config->skin);
60  // Check received variables (delete the basic variables such as mo, act, module_srl, page)
62  unset($obj->act);
63  unset($obj->module_srl);
64  unset($obj->page);
65  // Separately handle if the extra_vars is an image type in the original skin_info
66  if($skin_info->extra_vars)
67  {
68  foreach($skin_info->extra_vars as $vars)
69  {
70  if($vars->type!='image') continue;
71 
72  $image_obj = $obj->{$vars->name};
73  // Get a variable on a request to delete
74  $del_var = $obj->{"del_".$vars->name};
75  unset($obj->{"del_".$vars->name});
76  if($del_var == 'Y')
77  {
78  FileHandler::removeFile($module_info->{$vars->name});
79  continue;
80  }
81  // Use the previous data if not uploaded
82  if(!$image_obj['tmp_name'])
83  {
84  $obj->{$vars->name} = $module_info->{$vars->name};
85  continue;
86  }
87  // Ignore if the file is not successfully uploaded, and check uploaded file
88  if(!is_uploaded_file($image_obj['tmp_name']) || !checkUploadedFile($image_obj['tmp_name']))
89  {
90  unset($obj->{$vars->name});
91  continue;
92  }
93  // Ignore if the file is not an image
94  if(!preg_match("/\.(jpg|jpeg|gif|png)$/i", $image_obj['name']))
95  {
96  unset($obj->{$vars->name});
97  continue;
98  }
99  // Upload the file to a path
100  $path = sprintf("./files/attach/images/%s/", $module_srl);
101  // Create a directory
102  if(!FileHandler::makeDir($path)) return false;
103 
104  $filename = $path.$image_obj['name'];
105  // Move the file
106  if(!move_uploaded_file($image_obj['tmp_name'], $filename))
107  {
108  unset($obj->{$vars->name});
109  continue;
110  }
111  // Change a variable
112  unset($obj->{$vars->name});
113  $obj->{$vars->name} = $filename;
114  }
115  }
116  // Serialize and save
117  $args->skin_vars = serialize($obj);
118 
119  $oModuleController = getController('module');
120  $output = $oModuleController->insertModuleConfig('integration_search',$args);
121 
122  $this->setMessage('success_updated', 'info');
123 
124  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispIntegration_searchAdminSkinInfo');
125  return $this->setRedirectUrl($returnUrl, $output);
126  }
127 }
128 /* End of file integration_search.admin.controller.php */
129 /* Location: ./modules/integration_search/integration_search.admin.controller.php */
$oModuleModel
Definition: ko.install.php:236
getController($module_name)
Definition: func.inc.php:90
removeFile($filename)
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
$module_info
Definition: ko.install.php:289
getNotEncodedUrl()
Definition: func.inc.php:316
$args
Definition: ko.install.php:185
$module_info
an object containing the module information
setRedirectUrl($url= './', $output=NULL)
makeDir($path_string)
getModel($module_name)
Definition: func.inc.php:145
$module_srl
Definition: ko.install.php:254
$oModuleController
Definition: ko.install.php:287
checkUploadedFile($file)
Definition: func.inc.php:1165