XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
autoinstall.admin.view.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
9 {
10 
16 
21  var $ftp_set = FALSE;
22 
28  function init()
29  {
30  $template_path = sprintf("%stpl/", $this->module_path);
31  Context::set('original_site', _XE_LOCATION_SITE_);
34 
35  $ftp_info = Context::getFTPInfo();
36  if(!$ftp_info->ftp_root_path)
37  {
38  Context::set('show_ftp_note', TRUE);
39  }
40  else
41  {
42  $this->ftp_set = TRUE;
43  }
44 
45  $this->dispCategory();
46  $oModel = getModel('autoinstall');
47  Context::set('tCount', $oModel->getPackageCount(NULL));
48  Context::set('iCount', $oModel->getInstalledPackageCount());
49  }
50 
90  function rearrange(&$item, &$targets)
91  {
92  $ret = new stdClass();
93  foreach($targets as $target)
94  {
95  $ret->{$target} = $item->{$target}->body;
96  }
97  return $ret;
98  }
99 
170  function rearranges($items, $packages = null)
171  {
172  if(!is_array($items))
173  {
174  $items = array($items);
175  }
176 
177  $item_list = array();
178  $targets = array('category_srl', 'package_srl', 'item_screenshot_url', 'package_voted', 'package_voter', 'package_description', 'package_downloaded', 'item_regdate', 'title', 'item_version', 'package_star', 'depfrom');
179  $targetpackages = array();
180 
181  foreach($items as $item)
182  {
183  $targetpackages[$item->package_srl->body] = 0;
184  }
185 
186  $oModel = getModel('autoinstall');
187 
188  if($package == null)
189  {
190  $packages = $oModel->getInstalledPackages(array_keys($targetpackages));
191  }
192 
193  $depto = array();
194 
195  foreach($items as $item)
196  {
197  $v = $this->rearrange($item, $targets);
198  $v->item_screenshot_url = str_replace('./', _XE_DOWNLOAD_SERVER_, $v->item_screenshot_url);
199  $v->category = $this->categories[$v->category_srl]->title;
200  $v->url = _XE_LOCATION_SITE_ . '?mid=download&package_srl=' . $v->package_srl;
201 
202  if($packages[$v->package_srl])
203  {
204  $v->current_version = $packages[$v->package_srl]->current_version;
205  $v->need_update = $packages[$v->package_srl]->need_update;
206  $v->type = $oModel->getTypeFromPath($packages[$v->package_srl]->path);
207 
208  if($this->ftp_set && $v->depfrom)
209  {
210  $depfrom = explode(",", $v->depfrom);
211  foreach($depfrom as $package_srl)
212  {
213  $depto[$package_srl][] = $v->package_srl;
214  }
215  }
216 
217  if($v->type == "core")
218  {
219  $v->avail_remove = FALSE;
220  }
221  else if($v->type == "module")
222  {
223  $v->avail_remove = $oModel->checkRemovable($packages[$v->package_srl]->path);
224  }
225  else
226  {
227  $v->avail_remove = TRUE;
228  }
229  }
230  $item_list[$v->package_srl] = $v;
231  }
232 
233  if(count($depto) > 0)
234  {
235  $installed = $oModel->getInstalledPackages(implode(",", array_keys($depto)));
236  foreach($installed as $key => $val)
237  {
238  $path = $val->path;
239  $type = $oModel->getTypeFromPath($path);
240 
241  if(!$type || $type == "core")
242  {
243  continue;
244  }
245 
246  $config_file = $oModel->getConfigFilePath($type);
247  if(!$config_file)
248  {
249  continue;
250  }
251 
252  $xml = new XmlParser();
253  $xmlDoc = $xml->loadXmlFile(FileHandler::getRealPath($path) . $config_file);
254  if(!$xmlDoc)
255  {
256  continue;
257  }
258 
259  if($type == "drcomponent")
260  {
261  $type = "component";
262  }
263  if($type == "style" || $type == "m.skin")
264  {
265  $type = "skin";
266  }
267  if($type == "m.layout")
268  {
269  $type = "layout";
270  }
271  $title = $xmlDoc->{$type}->title->body;
272  $installed[$key]->title = $title;
273  }
274 
275  Context::set('installed', $installed);
276  $oSecurity = new Security();
277  $oSecurity->encodeHTML('installed..');
278 
279  foreach($installed as $key => $val)
280  {
281  foreach($depto[$key] as $package_srl)
282  {
283  $item_list[$package_srl]->avail_remove = false;
284  $item_list[$package_srl]->deps[] = $key;
285  }
286  }
287  }
288 
289  return $item_list;
290  }
291 
298  {
299  $page = Context::get('page');
300  if(!$page)
301  {
302  $page = 1;
303  }
304  Context::set('page', $page);
305 
306  $oModel = getModel('autoinstall');
307  $output = $oModel->getInstalledPackageList($page);
308  $package_list = $output->data;
309 
310  $params["act"] = "getResourceapiPackages";
311  $params["package_srls"] = implode(",", array_keys($package_list));
312  $body = XmlGenerater::generate($params);
313  $buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml");
314  $xml_lUpdate = new XmlParser();
315  $xmlDoc = $xml_lUpdate->parse($buff);
316  if($xmlDoc && $xmlDoc->response->packagelist->item)
317  {
318  $item_list = $this->rearranges($xmlDoc->response->packagelist->item, $package_list);
319  $res = array();
320  foreach($package_list as $package_srl => $package)
321  {
322  if($item_list[$package_srl])
323  {
324  $res[] = $item_list[$package_srl];
325  }
326  }
327  Context::set('item_list', $res);
328  }
329 
330  if(count($package_list) != count($res))
331  {
332  $localPackageSrls = array_keys($package_list);
333  $remotePackageSrls = array_keys($item_list);
334  $targetPackageSrls = array_diff($localPackageSrls, $remotePackageSrls);
335  $countDiff = count($targetPackageSrls);
336  $output->page_navigation->total_count -= $countDiff;
337  }
338 
339  Context::set('page_navigation', $output->page_navigation);
340 
341  $this->setTemplateFile('index');
342 
343  $security = new Security();
344  $security->encodeHTML('item_list..');
345  }
346 
353  {
354  $package_srl = Context::get('package_srl');
355  if(!$package_srl)
356  {
357  return $this->dispAutoinstallAdminIndex();
358  }
359 
360  $oAdminModel = getAdminModel('autoinstall');
361  $package = $oAdminModel->getInstallInfo($package_srl);
362 
363  Context::set("package", $package);
364  Context::set('contain_core', $package->contain_core);
365 
366  if(!$_SESSION['ftp_password'])
367  {
368  Context::set('need_password', TRUE);
369  }
370 
371  $output = $oAdminModel->checkUseDirectModuleInstall($package);
372  if($output->toBool()==TRUE)
373  {
374  Context::set('show_ftp_note', FALSE);
375  }
376  Context::set('directModuleInstall', $output);
377 
378  $this->setTemplateFile('install');
379 
380  $security = new Security();
381  $security->encodeHTML('package.', 'package.depends..');
382  }
383 
390  {
391  $oModuleModel = getModel('module');
392  $config = $oModuleModel->getModuleConfig('autoinstall');
393  $ftp_info = Context::getFTPInfo();
394  if(!$ftp_info->ftp_root_path)
395  {
396  Context::set('show_ftp_note', TRUE);
397  }
398 
399  $this->setTemplateFile('index');
400 
401  $params = array();
402  $params["act"] = "getResourceapiLastupdate";
403  $body = XmlGenerater::generate($params);
404  $buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml");
405  $xml_lUpdate = new XmlParser();
406  $lUpdateDoc = $xml_lUpdate->parse($buff);
407  $updateDate = $lUpdateDoc->response->updatedate->body;
408 
409  if(!$updateDate)
410  {
411  return $this->stop('msg_connection_fail');
412  }
413 
414  $oModel = getModel('autoinstall');
415  $item = $oModel->getLatestPackage();
416  if(!$item || $item->updatedate < $updateDate || count($this->categories) < 1)
417  {
418  $oController = getAdminController('autoinstall');
419  $oController->_updateinfo();
420 
421  if(!$_SESSION['__XE_EASYINSTALL_REDIRECT__'])
422  {
423  header('location: ' . getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAutoinstallAdminIndex'));
424  $_SESSION['__XE_EASYINSTALL_REDIRECT__'] = TRUE;
425  return;
426  }
427  }
428  unset($_SESSION['__XE_EASYINSTALL_REDIRECT__']);
429 
430  $page = Context::get('page');
431  if(!$page)
432  {
433  $page = 1;
434  }
435  Context::set('page', $page);
436 
437  $order_type = Context::get('order_type');
438  if(!in_array($order_type, array('asc', 'desc')))
439  {
440  $order_type = 'desc';
441  }
442  Context::set('order_type', $order_type);
443 
444  $order_target = Context::get('order_target');
445  if(!in_array($order_target, array('newest', 'download', 'popular')))
446  {
447  $order_target = 'newest';
448  }
449  Context::set('order_target', $order_target);
450 
451  $search_keyword = Context::get('search_keyword');
452 
453  $childrenList = Context::get('childrenList');
454  $category_srl = Context::get('category_srl');
455  if($childrenList)
456  {
457  $params["category_srl"] = $childrenList;
458  }
459  else if($category_srl)
460  {
461  $params["category_srl"] = $category_srl;
462  }
463 
464  $params["act"] = "getResourceapiPackagelist";
465  $params["order_target"] = $order_target;
466  $params["order_type"] = $order_type;
467  $params["page"] = $page;
468  if($search_keyword)
469  {
470  $params["search_keyword"] = $search_keyword;
471  }
472  $xmlDoc = XmlGenerater::getXmlDoc($params);
473  if($xmlDoc && $xmlDoc->response->packagelist->item)
474  {
475  $item_list = $this->rearranges($xmlDoc->response->packagelist->item);
476  Context::set('item_list', $item_list);
477  $array = array('total_count', 'total_page', 'cur_page', 'page_count', 'first_page', 'last_page');
478  $page_nav = $this->rearrange($xmlDoc->response->page_navigation, $array);
479  $page_navigation = new PageHandler($page_nav->total_count, $page_nav->total_page, $page_nav->cur_page, 5);
480  Context::set('page_navigation', $page_navigation);
481  }
482 
483  $security = new Security();
484  $security->encodeHTML('package.', 'package.depends..', 'item_list..');
485  $security->encodeHTML('search_target', 'search_keyword', 'order_target', 'order_type');
486  }
487 
493  function dispCategory()
494  {
495  $oModel = getModel('autoinstall');
496  $this->categories = $oModel->getCategoryList();
497  Context::set('categories', $this->categories);
498  }
499 
506  {
507  $package_srl = Context::get('package_srl');
508  if(!$package_srl)
509  {
510  return $this->dispAutoinstallAdminIndex();
511  }
512 
513  $oModel = getModel('autoinstall');
514  $oAdminModel = getAdminModel('autoinstall');
515  $installedPackage = $oModel->getInstalledPackage($package_srl);
516  if(!$installedPackage)
517  {
518  return $this->dispAutoinstallAdminInstalledPackages();
519  }
520 
521  if(!$_SESSION['ftp_password'])
522  {
523  Context::set('need_password', TRUE);
524  }
525 
526  $installedPackage = $oModel->getPackage($package_srl);
527  $path = $installedPackage->path;
528  $type = $oModel->getTypeFromPath($path);
529 
530  if(!$type || $type == "core")
531  {
532  return $this->stop("msg_invalid_request");
533  }
534 
535  $config_file = $oModel->getConfigFilePath($type);
536  if(!$config_file)
537  {
538  return $this->stop("msg_invalid_request");
539  }
540 
541  $output = $oAdminModel->checkUseDirectModuleInstall($installedPackage);
542  if($output->toBool()==TRUE)
543  {
544  Context::set('show_ftp_note', FALSE);
545  }
546  Context::set('directModuleInstall', $output);
547 
548  $params["act"] = "getResourceapiPackages";
549  $params["package_srls"] = $package_srl;
550  $body = XmlGenerater::generate($params);
551  $buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml");
552  $xml_lUpdate = new XmlParser();
553  $xmlDoc = $xml_lUpdate->parse($buff);
554  if($xmlDoc && $xmlDoc->response->packagelist->item)
555  {
556  $item_list = $this->rearranges($xmlDoc->response->packagelist->item);
557  $installedPackage->title = $item_list[$package_srl]->title;
558  $installedPackage->type = $item_list[$package_srl]->category;
559  $installedPackage->avail_remove = $item_list[$package_srl]->avail_remove;
560  $installedPackage->deps = $item_list[$package_srl]->deps;
561  Context::set('package', $installedPackage);
562  $this->setTemplateFile('uninstall');
563  Context::addJsFilter($this->module_path . 'tpl/filter', 'uninstall_package.xml');
564 
565  $security = new Security();
566  $security->encodeHTML('package.');
567 
568  $this->setTemplateFile('uninstall');
569  }
570  else
571  {
572  return $this->stop('msg_connection_fail');
573  }
574  }
575 
576 }
577 /* End of file autoinstall.admin.view.php */
578 /* Location: ./modules/autoinstall/autoinstall.admin.view.php */
$oModuleModel
Definition: ko.install.php:236
$template_path
a path of directory where template files reside
$output
Definition: ko.install.php:193
set($key, $val, $set_to_get_vars=0)
getNotEncodedUrl()
Definition: func.inc.php:316
rearrange(&$item, &$targets)
getRemoteResource($url, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
const _XE_DOWNLOAD_SERVER_
Definition: config.inc.php:79
getXmlDoc(&$params)
getAdminModel($module_name)
Definition: func.inc.php:156
generate(&$params)
getRealPath($source)
const _XE_LOCATION_SITE_
Definition: config.inc.php:74
rearranges($items, $packages=null)
getModel($module_name)
Definition: func.inc.php:145
getAdminController($module_name)
Definition: func.inc.php:101
addJsFilter($path, $filename)