XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
autoinstall.admin.model.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
9 {
10 
11  var $layout_category_srl = 18322954;
13  var $module_skin_category_srl = 18322943;
15 
19  function preProcParam(&$order_target, &$order_type, &$page)
20  {
21  $order_target_array = array('newest' => 1, 'download' => 1, 'popular' => 1);
22  if(!isset($order_target_array[$order_target]))
23  {
24  $order_target = 'newest';
25  }
26 
27  $order_type_array = array('asc' => 1, 'desc' => 1);
28  if(!isset($order_type_array[$order_type]))
29  {
30  $order_type = 'desc';
31  }
32 
33  $page = (int) $page;
34  if($page < 1)
35  {
36  $page = 1;
37  }
38  }
39 
44  {
45  $search_keyword = Context::get('search_keyword');
46  $order_target = Context::get('order_target');
47  $order_type = Context::get('order_type');
48  $page = Context::get('page');
49 
50  $this->preProcParam($order_target, $order_type, $page);
51  $this->getPackageList('menu', $order_target, $order_type, $page, $search_keyword);
52  }
53 
58  {
59  $search_keyword = Context::get('search_keyword');
60  $order_target = Context::get('order_target');
61  $order_type = Context::get('order_type');
62  $page = Context::get('page');
63 
64  $type_array = array('M' => 1, 'P' => 1);
65  $type = Context::get('type');
66  if(!isset($type_array[$type]))
67  {
68  $type = 'P';
69  }
70 
71  if($type == 'P')
72  {
73  $category_srl = $this->layout_category_srl;
74  }
75  else
76  {
77  $category_srl = $this->mobile_layout_category_srl;
78  }
79 
80  $this->preProcParam($order_target, $order_type, $page);
81  $this->getPackageList('layout', $order_target, $order_type, $page, $search_keyword, $category_srl);
82  }
83 
88  {
90  $search_keyword = Context::get('search_keyword');
91  $order_target = Context::get('order_target');
92  $order_type = Context::get('order_type');
93  $page = Context::get('page');
94  $parent_program = Context::get('parent_program');
95 
96  $type_array = array('M' => 1, 'P' => 1);
97  $type = Context::get('type');
98  if(!isset($type_array[$type]))
99  {
100  $type = 'P';
101  }
102 
103  if($type == 'P')
104  {
105  $category_srl = $this->module_skin_category_srl;
106  }
107  else
108  {
110  }
111 
112  $this->preProcParam($order_target, $order_type, $page);
113  $this->getPackageList('skin', $order_target, $order_type, $page, $search_keyword, $category_srl, $parent_program);
114  }
115 
119  function getPackageList($type, $order_target = 'newest', $order_type = 'desc', $page = '1', $search_keyword = NULL, $category_srl = NULL, $parent_program = NULL)
120  {
121  if($type == 'menu')
122  {
123  $params["act"] = "getResourceapiMenuPackageList";
124  }
125  elseif($type == 'skin')
126  {
127  $params["act"] = "getResourceapiSkinPackageList";
128  $params['parent_program'] = $parent_program;
129  }
130  else
131  {
132  $params["act"] = "getResourceapiPackagelist";
133  }
134 
135  $oAdminView = getAdminView('autoinstall');
136  $params["order_target"] = $order_target;
137  $params["order_type"] = $order_type;
138  $params["page"] = $page;
139 
140  if($category_srl)
141  {
142  $params["category_srl"] = $category_srl;
143  }
144 
145  if($search_keyword)
146  {
147  $params["search_keyword"] = $search_keyword;
148  }
149 
150  $xmlDoc = XmlGenerater::getXmlDoc($params);
151  if($xmlDoc && $xmlDoc->response->packagelist->item)
152  {
153  $item_list = $oAdminView->rearranges($xmlDoc->response->packagelist->item);
154  $this->add('item_list', $item_list);
155  $array = array('total_count', 'total_page', 'cur_page', 'page_count', 'first_page', 'last_page');
156  $page_nav = $oAdminView->rearrange($xmlDoc->response->page_navigation, $array);
157  $page_navigation = new PageHandler($page_nav->total_count, $page_nav->total_page, $page_nav->cur_page, 5);
158  $this->add('page_navigation', $page_navigation);
159  }
160  }
161 
166  {
167  $oAdminModel = getAdminModel('autoinstall');
168  $package = $oAdminModel->getInstallInfo(Context::get('package_srl'));
169 
170  $is_authed = 0;
171  $output = $oAdminModel->checkUseDirectModuleInstall($package);
172  if($output->toBool()==TRUE)
173  {
174  $is_authed = 1;
175  }
176  else
177  {
178  $ftp_info = Context::getFTPInfo();
179  if(!$ftp_info->ftp_root_path)
180  {
181  $is_authed = -1;
182  }
183  else
184  {
185  $is_authed = (int) isset($_SESSION['ftp_password']);
186  }
187  }
188 
189  $this->add('is_authed', $is_authed);
190  }
191 
195  public function getNeedUpdateList()
196  {
197  $oModel = getModel('autoinstall');
198  $output = executeQueryArray('autoinstall.getNeedUpdate');
199  if(!is_array($output->data))
200  {
201  return NULL;
202  }
203 
204  $result = array();
205  $xml = new XmlParser();
206  foreach($output->data as $package)
207  {
208  $packageSrl = $package->package_srl;
209 
210  $packageInfo = new stdClass();
211  $packageInfo->currentVersion = $package->current_version;
212  $packageInfo->version = $package->version;
213  $packageInfo->type = $oModel->getTypeFromPath($package->path);
214  $packageInfo->url = $oModel->getUpdateUrlByPackageSrl($package->package_srl);
215 
216  if($packageInfo->type == 'core')
217  {
218  $title = 'XpressEngine';
219  }
220  else
221  {
222  $configFile = $oModel->getConfigFilePath($packageInfo->type);
223  $xmlDoc = $xml->loadXmlFile(FileHandler::getRealPath($package->path) . $configFile);
224 
225  if($xmlDoc)
226  {
227  $type = $packageInfo->type;
228  if($type == "drcomponent")
229  {
230  $type = "component";
231  }
232  if($type == "style" || $type == "m.skin")
233  {
234  $type = "skin";
235  }
236  if($type == "m.layout")
237  {
238  $type = "layout";
239  }
240  $title = $xmlDoc->{$type}->title->body;
241  }
242  else
243  {
244  $pathInfo = explode('/', $package->path);
245  $title = $pathInfo[count($pathInfo) - 1];
246  }
247  }
248  $packageInfo->title = $title;
249 
250  $result[] = $packageInfo;
251  }
252 
253  return $result;
254  }
255 
262  public function getInstallInfo($packageSrl)
263  {
264  $params["act"] = "getResourceapiInstallInfo";
265  $params["package_srl"] = $packageSrl;
266  $xmlDoc = XmlGenerater::getXmlDoc($params);
267  $oModel = getModel('autoinstall');
268 
269  $targetpackages = array();
270  if($xmlDoc)
271  {
272  $xmlPackage = $xmlDoc->response->package;
273  $package = new stdClass();
274  $package->package_srl = $xmlPackage->package_srl->body;
275  $package->title = $xmlPackage->title->body;
276  $package->package_description = $xmlPackage->package_description->body;
277  $package->version = $xmlPackage->version->body;
278  $package->path = $xmlPackage->path->body;
279  if($xmlPackage->depends)
280  {
281  if(!is_array($xmlPackage->depends->item))
282  {
283  $xmlPackage->depends->item = array($xmlPackage->depends->item);
284  }
285 
286  $package->depends = array();
287  foreach($xmlPackage->depends->item as $item)
288  {
289  $dep_item = new stdClass();
290  $dep_item->package_srl = $item->package_srl->body;
291  $dep_item->title = $item->title->body;
292  $dep_item->version = $item->version->body;
293  $dep_item->path = $item->path->body;
294  $package->depends[] = $dep_item;
295  $targetpackages[$dep_item->package_srl] = 1;
296  }
297 
298  $packages = $oModel->getInstalledPackages(array_keys($targetpackages));
299  $package->deplist = "";
300  foreach($package->depends as $key => $dep)
301  {
302  if(!$packages[$dep->package_srl])
303  {
304  $package->depends[$key]->installed = FALSE;
305  $package->package_srl .= "," . $dep->package_srl;
306  }
307  else
308  {
309  $package->depends[$key]->installed = TRUE;
310  $package->depends[$key]->cur_version = $packages[$dep->package_srl]->current_version;
311  if(version_compare($dep->version, $packages[$dep->package_srl]->current_version, ">"))
312  {
313  $package->depends[$key]->need_update = TRUE;
314  $package->package_srl .= "," . $dep->package_srl;
315 
316  if($dep->path === '.')
317  {
318  $package->contain_core = TRUE;
319  $package->contain_core_version = $dep->version;
320  }
321  }
322  else
323  {
324  $package->need_update = FALSE;
325  }
326  }
327  }
328  }
329 
330  $installedPackage = $oModel->getInstalledPackage($packageSrl);
331  if($installedPackage)
332  {
333  $package->installed = TRUE;
334  $package->cur_version = $installedPackage->current_version;
335  $package->need_update = version_compare($package->version, $installedPackage->current_version, ">");
336  }
337  }
338 
339  return $package;
340  }
341 
346  {
347  $packageSrl = Context::get('package_srl');
348  if(!$packageSrl)
349  {
350  return new BaseObject(-1, 'msg_invalid_request');
351  }
352 
353  $package = $this->getInstallInfo($packageSrl);
354  $this->add('package', $package);
355  }
356 
357  public function checkUseDirectModuleInstall($package)
358  {
359  $directModuleInstall = TRUE;
360  $arrUnwritableDir = array();
361  $output = $this->isWritableDir($package->path);
362  if($output->toBool()==FALSE)
363  {
364  $directModuleInstall = FALSE;
365  $arrUnwritableDir[] = $output->get('path');
366  }
367 
368  foreach($package->depends as $dep)
369  {
370  $output = $this->isWritableDir($dep->path);
371  if($output->toBool()==FALSE)
372  {
373  $directModuleInstall = FALSE;
374  $arrUnwritableDir[] = $output->get('path');
375  }
376  }
377 
378  if($directModuleInstall==FALSE)
379  {
380  $output = new BaseObject(-1, 'msg_direct_inall_invalid');
381  $output->add('path', $arrUnwritableDir);
382  return $output;
383  }
384 
385  return new BaseObject();
386  }
387 
388  public function isWritableDir($path)
389  {
390  $path_list = explode('/', dirname($path));
391  $real_path = './';
392 
393  while($path_list)
394  {
395  $check_path = realpath($real_path . implode('/', $path_list));
396  if(FileHandler::isDir($check_path))
397  {
398  break;
399  }
400  array_pop($path_list);
401  }
402 
403  if(FileHandler::isWritableDir($check_path)==FALSE)
404  {
405  $output = new BaseObject(-1, 'msg_unwritable_directory');
406  $output->add('path', FileHandler::getRealPath($check_path));
407  return $output;
408  }
409  return new BaseObject();
410  }
411 
412 }
413 /* End of file autoinstall.admin.model.php */
414 /* Location: ./modules/autoinstall/autoinstall.admin.model.php */
getPackageList($type, $order_target= 'newest', $order_type= 'desc', $page= '1', $search_keyword=NULL, $category_srl=NULL, $parent_program=NULL)
setRequestMethod($type= '')
$output
Definition: ko.install.php:193
add($key, $val)
preProcParam(&$order_target, &$order_type, &$page)
getXmlDoc(&$params)
getAdminModel($module_name)
Definition: func.inc.php:156
getRealPath($source)
getAdminView($module_name)
Definition: func.inc.php:134
getModel($module_name)
Definition: func.inc.php:145
executeQueryArray($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:219