PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/admin/admin.admin.model.php

https://github.com/prologos/xe-core
PHP | 964 lines | 734 code | 123 blank | 107 comment | 100 complexity | 30d3caa1d6eddc32ca5f0eb923c59735 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /* Copyright (C) NAVER <http://www.navercorp.com> */
  3. /**
  4. * adminAdminModel class
  5. * admin model class of admin module
  6. * @author NAVER (developers@xpressengine.com)
  7. * @package /modules/admin
  8. * @version 0.1
  9. */
  10. class adminAdminModel extends admin
  11. {
  12. /**
  13. * Ftp root path
  14. * @var string
  15. */
  16. var $pwd;
  17. /**
  18. * Buffer for Admin GNB menu
  19. * @var string
  20. */
  21. var $gnbLangBuffer;
  22. /**
  23. * Find XE installed path on sftp
  24. */
  25. function getSFTPPath()
  26. {
  27. $ftp_info = Context::getRequestVars();
  28. if(!$ftp_info->ftp_host)
  29. {
  30. $ftp_info->ftp_host = "127.0.0.1";
  31. }
  32. if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
  33. {
  34. $ftp_info->ftp_port = '22';
  35. }
  36. $connection = ssh2_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
  37. if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password))
  38. {
  39. return new Object(-1, 'msg_ftp_invalid_auth_info');
  40. }
  41. $sftp = ssh2_sftp($connection);
  42. // create temp file
  43. $pin = $_SERVER['REQUEST_TIME'];
  44. FileHandler::writeFile('./files/cache/ftp_check', $pin);
  45. // create path candidate
  46. $xe_path = _XE_PATH_;
  47. $path_info = array_reverse(explode('/', _XE_PATH_));
  48. array_pop($path_info); // remove last '/'
  49. $path_candidate = array();
  50. $temp = '';
  51. foreach($path_info as $path)
  52. {
  53. $temp = '/' . $path . $temp;
  54. $path_candidate[] = $temp;
  55. }
  56. // try
  57. foreach($path_candidate as $path)
  58. {
  59. // upload check file
  60. if(!@ssh2_scp_send($connection, FileHandler::getRealPath('./files/cache/ftp_check'), $path . 'ftp_check.html'))
  61. {
  62. continue;
  63. }
  64. // get check file
  65. $result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html');
  66. // delete temp check file
  67. @ssh2_sftp_unlink($sftp, $path . 'ftp_check.html');
  68. // found
  69. if($result == $pin)
  70. {
  71. $found_path = $path;
  72. break;
  73. }
  74. }
  75. FileHandler::removeFile('./files/cache/ftp_check', $pin);
  76. if($found_path)
  77. {
  78. $this->add('found_path', $found_path);
  79. }
  80. }
  81. function getFTPPath()
  82. {
  83. $ftp_info = Context::getRequestVars();
  84. if(!$ftp_info->ftp_host)
  85. {
  86. $ftp_info->ftp_host = "127.0.0.1";
  87. }
  88. if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
  89. {
  90. $ftp_info->ftp_port = '22';
  91. }
  92. $connection = ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
  93. if(!$connection)
  94. {
  95. return new Object(-1, sprintf(Context::getLang('msg_ftp_not_connected'), $ftp_host));
  96. }
  97. $login_result = @ftp_login($connection, $ftp_info->ftp_user, $ftp_info->ftp_password);
  98. if(!$login_result)
  99. {
  100. ftp_close($connection);
  101. return new Object(-1, 'msg_ftp_invalid_auth_info');
  102. }
  103. // create temp file
  104. $pin = $_SERVER['REQUEST_TIME'];
  105. FileHandler::writeFile('./files/cache/ftp_check', $pin);
  106. // create path candidate
  107. $xe_path = _XE_PATH_;
  108. $path_info = array_reverse(explode('/', _XE_PATH_));
  109. array_pop($path_info); // remove last '/'
  110. $path_candidate = array();
  111. $temp = '';
  112. foreach($path_info as $path)
  113. {
  114. $temp = '/' . $path . $temp;
  115. $path_candidate[] = $temp;
  116. }
  117. // try
  118. foreach($path_candidate as $path)
  119. {
  120. // upload check file
  121. if(!ftp_put($connection, $path . 'ftp_check.html', FileHandler::getRealPath('./files/cache/ftp_check'), FTP_BINARY))
  122. {
  123. continue;
  124. }
  125. // get check file
  126. $result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html');
  127. // delete temp check file
  128. ftp_delete($connection, $path . 'ftp_check.html');
  129. // found
  130. if($result == $pin)
  131. {
  132. $found_path = $path;
  133. break;
  134. }
  135. }
  136. FileHandler::removeFile('./files/cache/ftp_check', $pin);
  137. if($found_path)
  138. {
  139. $this->add('found_path', $found_path);
  140. }
  141. }
  142. /**
  143. * Find XE installed path on ftp
  144. */
  145. function getAdminFTPPath()
  146. {
  147. Context::loadLang(_XE_PATH_ . 'modules/autoinstall/lang');
  148. @set_time_limit(5);
  149. require_once(_XE_PATH_ . 'libs/ftp.class.php');
  150. $ftp_info = Context::getRequestVars();
  151. if(!$ftp_info->ftp_user || !$ftp_info->ftp_password)
  152. {
  153. return new Object(1, 'msg_ftp_invalid_auth_info');
  154. }
  155. if(!$ftp_info->ftp_host)
  156. {
  157. $ftp_info->ftp_host = '127.0.0.1';
  158. }
  159. if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
  160. {
  161. $ftp_info->ftp_port = '21';
  162. }
  163. if($ftp_info->sftp == 'Y')
  164. {
  165. if(!function_exists('ssh2_sftp'))
  166. {
  167. return new Object(-1, 'disable_sftp_support');
  168. }
  169. return $this->getSFTPPath();
  170. }
  171. if($ftp_info->ftp_pasv == 'N')
  172. {
  173. if(function_exists('ftp_connect'))
  174. {
  175. return $this->getFTPPath();
  176. }
  177. $ftp_info->ftp_pasv = "Y";
  178. }
  179. $oFTP = new ftp();
  180. if(!$oFTP->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port))
  181. {
  182. return new Object(1, sprintf(Context::getLang('msg_ftp_not_connected'), $ftp_info->ftp_host));
  183. }
  184. if(!$oFTP->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
  185. {
  186. return new Object(1, 'msg_ftp_invalid_auth_info');
  187. }
  188. // create temp file
  189. $pin = $_SERVER['REQUEST_TIME'];
  190. FileHandler::writeFile('./files/cache/ftp_check', $pin);
  191. // create path candidate
  192. $xe_path = _XE_PATH_;
  193. $path_info = array_reverse(explode('/', _XE_PATH_));
  194. array_pop($path_info); // remove last '/'
  195. $path_candidate = array();
  196. $temp = '';
  197. foreach($path_info as $path)
  198. {
  199. $temp = '/' . $path . $temp;
  200. $path_candidate[] = $temp;
  201. }
  202. // try
  203. foreach($path_candidate as $path)
  204. {
  205. // upload check file
  206. if(!$oFTP->ftp_put($path . 'ftp_check.html', FileHandler::getRealPath('./files/cache/ftp_check')))
  207. {
  208. continue;
  209. }
  210. // get check file
  211. $result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html');
  212. // delete temp check file
  213. $oFTP->ftp_delete($path . 'ftp_check.html');
  214. // found
  215. if($result == $pin)
  216. {
  217. $found_path = $path;
  218. break;
  219. }
  220. }
  221. FileHandler::removeFile('./files/cache/ftp_check', $pin);
  222. if($found_path)
  223. {
  224. $this->add('found_path', $found_path);
  225. }
  226. }
  227. /**
  228. * Add file list to Object after sftp connect
  229. * @return void|Object
  230. */
  231. function getSFTPList()
  232. {
  233. $ftp_info = Context::getRequestVars();
  234. if(!$ftp_info->ftp_host)
  235. {
  236. $ftp_info->ftp_host = "127.0.0.1";
  237. }
  238. $connection = ssh2_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
  239. if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password))
  240. {
  241. return new Object(-1, 'msg_ftp_invalid_auth_info');
  242. }
  243. $sftp = ssh2_sftp($connection);
  244. $curpwd = "ssh2.sftp://$sftp" . $this->pwd;
  245. $dh = @opendir($curpwd);
  246. if(!$dh)
  247. {
  248. return new Object(-1, 'msg_ftp_invalid_path');
  249. }
  250. $list = array();
  251. while(($file = readdir($dh)) !== FALSE)
  252. {
  253. if(is_dir($curpwd . $file))
  254. {
  255. $file .= "/";
  256. }
  257. else
  258. {
  259. continue;
  260. }
  261. $list[] = $file;
  262. }
  263. closedir($dh);
  264. $this->add('list', $list);
  265. }
  266. /**
  267. * Add file list to Object after ftp connect
  268. * @return void|Object
  269. */
  270. function getAdminFTPList()
  271. {
  272. Context::loadLang(_XE_PATH_ . 'modules/autoinstall/lang');
  273. @set_time_limit(5);
  274. require_once(_XE_PATH_ . 'libs/ftp.class.php');
  275. $ftp_info = Context::getRequestVars();
  276. if(!$ftp_info->ftp_user || !$ftp_info->ftp_password)
  277. {
  278. return new Object(-1, 'msg_ftp_invalid_auth_info');
  279. }
  280. $this->pwd = $ftp_info->ftp_root_path;
  281. if(!$ftp_info->ftp_host)
  282. {
  283. $ftp_info->ftp_host = "127.0.0.1";
  284. }
  285. if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
  286. {
  287. $ftp_info->ftp_port = "21";
  288. }
  289. if($ftp_info->sftp == 'Y')
  290. {
  291. if(!function_exists('ssh2_sftp'))
  292. {
  293. return new Object(-1, 'disable_sftp_support');
  294. }
  295. return $this->getSFTPList();
  296. }
  297. $oFtp = new ftp();
  298. if($oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port))
  299. {
  300. if($oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
  301. {
  302. $_list = $oFtp->ftp_rawlist($this->pwd);
  303. $oFtp->ftp_quit();
  304. }
  305. else
  306. {
  307. return new Object(-1, 'msg_ftp_invalid_auth_info');
  308. }
  309. }
  310. $list = array();
  311. if($_list)
  312. {
  313. foreach($_list as $k => $v)
  314. {
  315. $src = new stdClass();
  316. $src->data = $v;
  317. $res = Context::convertEncoding($src);
  318. $v = $res->data;
  319. if(strpos($v, 'd') === 0 || strpos($v, '<DIR>'))
  320. {
  321. $list[] = substr(strrchr($v, ' '), 1) . '/';
  322. }
  323. }
  324. }
  325. else
  326. {
  327. return new Object(-1, 'msg_ftp_no_directory');
  328. }
  329. $this->add('list', $list);
  330. }
  331. /**
  332. * Parameter arrange for send to XE collect server
  333. * @param string $type 'WORKING', 'INSTALL'
  334. * @return string
  335. */
  336. function getEnv($type = 'WORKING')
  337. {
  338. $skip = array(
  339. 'ext' => array('pcre', 'json', 'hash', 'dom', 'session', 'spl', 'standard', 'date', 'ctype', 'tokenizer', 'apache2handler', 'filter', 'posix', 'reflection', 'pdo')
  340. , 'module' => array('addon', 'admin', 'autoinstall', 'comment', 'communication', 'counter', 'document', 'editor', 'file', 'importer', 'install', 'integration_search', 'layout', 'member', 'menu', 'message', 'module', 'opage', 'page', 'point', 'poll', 'rss', 'session', 'spamfilter', 'tag', 'trackback', 'trash', 'widget')
  341. , 'addon' => array('autolink', 'blogapi', 'captcha', 'counter', 'member_communication', 'member_extra_info', 'mobile', 'openid_delegation_id', 'point_level_icon', 'resize_image')
  342. , 'layout' => array('default')
  343. , 'widget' => array('content', 'language_select', 'login_info','mcontent')
  344. , 'widgetstyle' => array(),
  345. );
  346. $info = array();
  347. $db_info = Context::getDBInfo();
  348. $info['type'] = ($type != 'INSTALL' ? 'WORKING' : 'INSTALL');
  349. $info['location'] = _XE_LOCATION_;
  350. $info['package'] = _XE_PACKAGE_;
  351. $info['host'] = $db_type->default_url ? $db_type->default_url : getFullUrl();
  352. $info['app'] = $_SERVER['SERVER_SOFTWARE'];
  353. $info['xe_version'] = __XE_VERSION__;
  354. $info['php'] = phpversion();
  355. $info['db_type'] = Context::getDBType();
  356. $info['use_rewrite'] = $db_info->use_rewrite;
  357. $info['use_db_session'] = $db_info->use_db_session == 'Y' ? 'Y' : 'N';
  358. $info['use_ssl'] = $db_info->use_ssl;
  359. $info['phpext'] = '';
  360. foreach(get_loaded_extensions() as $ext)
  361. {
  362. $ext = strtolower($ext);
  363. if(in_array($ext, $skip['ext']))
  364. {
  365. continue;
  366. }
  367. $info['phpext'] .= '|' . $ext;
  368. }
  369. $info['phpext'] = substr($info['phpext'], 1);
  370. $info['module'] = '';
  371. $oModuleModel = getModel('module');
  372. $module_list = $oModuleModel->getModuleList();
  373. if($module_list) foreach($module_list as $module)
  374. {
  375. if(in_array($module->module, $skip['module']))
  376. {
  377. continue;
  378. }
  379. $info['module'] .= '|' . $module->module;
  380. }
  381. $info['module'] = substr($info['module'], 1);
  382. $info['addon'] = '';
  383. $oAddonAdminModel = getAdminModel('addon');
  384. $addon_list = $oAddonAdminModel->getAddonList();
  385. if($addon_list) foreach($addon_list as $addon)
  386. {
  387. if(in_array($addon->addon, $skip['addon']))
  388. {
  389. continue;
  390. }
  391. $info['addon'] .= '|' . $addon->addon;
  392. }
  393. $info['addon'] = substr($info['addon'], 1);
  394. $info['layout'] = "";
  395. $oLayoutModel = getModel('layout');
  396. $layout_list = $oLayoutModel->getDownloadedLayoutList();
  397. if($layout_list) foreach($layout_list as $layout)
  398. {
  399. if(in_array($layout->layout, $skip['layout']))
  400. {
  401. continue;
  402. }
  403. $info['layout'] .= '|' . $layout->layout;
  404. }
  405. $info['layout'] = substr($info['layout'], 1);
  406. $info['widget'] = "";
  407. $oWidgetModel = getModel('widget');
  408. $widget_list = $oWidgetModel->getDownloadedWidgetList();
  409. if($widget_list) foreach($widget_list as $widget)
  410. {
  411. if(in_array($widget->widget, $skip['widget']))
  412. {
  413. continue;
  414. }
  415. $info['widget'] .= '|' . $widget->widget;
  416. }
  417. $info['widget'] = substr($info['widget'], 1);
  418. $info['widgetstyle'] = "";
  419. $oWidgetModel = getModel('widget');
  420. $widgetstyle_list = $oWidgetModel->getDownloadedWidgetStyleList();
  421. if($widgetstyle_list) foreach($widgetstyle_list as $widgetstyle)
  422. {
  423. if(in_array($widgetstyle->widgetStyle, $skip['widgetstyle']))
  424. {
  425. continue;
  426. }
  427. $info['widgetstyle'] .= '|' . $widgetstyle->widgetStyle;
  428. }
  429. $info['widgetstyle'] = substr($info['widgetstyle'], 1);
  430. $param = '';
  431. foreach($info as $k => $v)
  432. {
  433. if($v)
  434. {
  435. $param .= sprintf('&%s=%s', $k, urlencode($v));
  436. }
  437. }
  438. $param = substr($param, 1);
  439. return $param;
  440. }
  441. /**
  442. * Return theme info list by theme directory list
  443. * @return array
  444. */
  445. function getThemeList()
  446. {
  447. $path = _XE_PATH_ . 'themes';
  448. $list = FileHandler::readDir($path);
  449. $theme_info = array();
  450. if(count($list) > 0)
  451. {
  452. foreach($list as $val)
  453. {
  454. $theme_info[$val] = $this->getThemeInfo($val);
  455. }
  456. }
  457. return $theme_info;
  458. }
  459. /**
  460. * Return theme info
  461. * @param string $theme_name
  462. * @param array $layout_list
  463. * @return object
  464. */
  465. function getThemeInfo($theme_name, $layout_list = NULL)
  466. {
  467. if($GLOBALS['__ThemeInfo__'][$theme_name])
  468. {
  469. return $GLOBALS['__ThemeInfo__'][$theme_name];
  470. }
  471. $info_file = _XE_PATH_ . 'themes/' . $theme_name . '/conf/info.xml';
  472. if(!file_exists($info_file))
  473. {
  474. return;
  475. }
  476. $oXmlParser = new XmlParser();
  477. $_xml_obj = $oXmlParser->loadXmlFile($info_file);
  478. if(!$_xml_obj->theme)
  479. {
  480. return;
  481. }
  482. $xml_obj = $_xml_obj->theme;
  483. // 스킨이름
  484. $theme_info = new stdClass();
  485. $theme_info->name = $theme_name;
  486. $theme_info->title = $xml_obj->title->body;
  487. $thumbnail = './themes/' . $theme_name . '/thumbnail.png';
  488. $theme_info->thumbnail = (FileHandler::exists($thumbnail)) ? $thumbnail : NULL;
  489. $theme_info->version = $xml_obj->version->body;
  490. $date_obj = new stdClass();
  491. sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
  492. $theme_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
  493. $theme_info->description = $xml_obj->description->body;
  494. $theme_info->path = './themes/' . $theme_name . '/';
  495. if(!is_array($xml_obj->publisher))
  496. {
  497. $publisher_list = array();
  498. $publisher_list[] = $xml_obj->publisher;
  499. }
  500. else
  501. {
  502. $publisher_list = $xml_obj->publisher;
  503. }
  504. $theme_info->publisher = array();
  505. foreach($publisher_list as $publisher)
  506. {
  507. $publisher_obj = new stdClass();
  508. $publisher_obj->name = $publisher->name->body;
  509. $publisher_obj->email_address = $publisher->attrs->email_address;
  510. $publisher_obj->homepage = $publisher->attrs->link;
  511. $theme_info->publisher[] = $publisher_obj;
  512. }
  513. $layout = $xml_obj->layout;
  514. $layout_path = $layout->directory->attrs->path;
  515. $layout_parse = explode('/', $layout_path);
  516. $layout_info = new stdClass();
  517. switch($layout_parse[1])
  518. {
  519. case 'themes' :
  520. $layout_info->name = $theme_name . '|@|' . $layout_parse[count($layout_parse) - 1];
  521. break;
  522. case 'layouts' :
  523. $layout_info->name = $layout_parse[count($layout_parse) - 1];
  524. break;
  525. }
  526. $layout_info->title = $layout_parse[count($layout_parse) - 1];
  527. $layout_info->path = $layout_path;
  528. $site_info = Context::get('site_module_info');
  529. // check layout instance
  530. $is_new_layout = TRUE;
  531. $oLayoutModel = getModel('layout');
  532. $layout_info_list = array();
  533. $layout_list = $oLayoutModel->getLayoutList($site_info->site_srl);
  534. if($layout_list)
  535. {
  536. foreach($layout_list as $val)
  537. {
  538. if($val->layout == $layout_info->name)
  539. {
  540. $is_new_layout = FALSE;
  541. $layout_info->layout_srl = $val->layout_srl;
  542. break;
  543. }
  544. }
  545. }
  546. if($is_new_layout)
  547. {
  548. $site_module_info = Context::get('site_module_info');
  549. $args = new stdClass();
  550. $args->site_srl = (int) $site_module_info->site_srl;
  551. $args->layout_srl = getNextSequence();
  552. $args->layout = $layout_info->name;
  553. $args->title = $layout_info->title;
  554. $args->layout_type = "P";
  555. // Insert into the DB
  556. $oLayoutAdminController = getAdminController('layout');
  557. $output = $oLayoutAdminController->insertLayout($args);
  558. $layout_info->layout_srl = $args->layout_srl;
  559. }
  560. $theme_info->layout_info = $layout_info;
  561. $skin_infos = $xml_obj->skininfos;
  562. if(is_array($skin_infos->skininfo))
  563. {
  564. $skin_list = $skin_infos->skininfo;
  565. }
  566. else
  567. {
  568. $skin_list = array($skin_infos->skininfo);
  569. }
  570. $oModuleModel = getModel('module');
  571. $skins = array();
  572. foreach($skin_list as $val)
  573. {
  574. $skin_info = new stdClass();
  575. unset($skin_parse);
  576. $skin_parse = explode('/', $val->directory->attrs->path);
  577. switch($skin_parse[1])
  578. {
  579. case 'themes' :
  580. $is_theme = TRUE;
  581. $module_name = $skin_parse[count($skin_parse) - 1];
  582. $skin_info->name = $theme_name . '|@|' . $module_name;
  583. break;
  584. case 'modules' :
  585. $is_theme = FALSE;
  586. $module_name = $skin_parse[2];
  587. $skin_info->name = $skin_parse[count($skin_parse) - 1];
  588. break;
  589. }
  590. $skin_info->path = $val->directory->attrs->path;
  591. $skin_info->is_theme = $is_theme;
  592. $skins[$module_name] = $skin_info;
  593. if($is_theme)
  594. {
  595. if(!$GLOBALS['__ThemeModuleSkin__'][$module_name])
  596. {
  597. $GLOBALS['__ThemeModuleSkin__'][$module_name] = array();
  598. $GLOBALS['__ThemeModuleSkin__'][$module_name]['skins'] = array();
  599. $moduleInfo = $oModuleModel->getModuleInfoXml($module_name);
  600. $GLOBALS['__ThemeModuleSkin__'][$module_name]['title'] = $moduleInfo->title;
  601. }
  602. $GLOBALS['__ThemeModuleSkin__'][$module_name]['skins'][$skin_info->name] = $oModuleModel->loadSkinInfo($skin_info->path, '', '');
  603. }
  604. }
  605. $theme_info->skin_infos = $skins;
  606. $GLOBALS['__ThemeInfo__'][$theme_name] = $theme_info;
  607. return $theme_info;
  608. }
  609. /**
  610. * Return theme module skin list
  611. * @return array
  612. */
  613. function getModulesSkinList()
  614. {
  615. if($GLOBALS['__ThemeModuleSkin__']['__IS_PARSE__'])
  616. {
  617. return $GLOBALS['__ThemeModuleSkin__'];
  618. }
  619. $searched_list = FileHandler::readDir('./modules');
  620. sort($searched_list);
  621. $searched_count = count($searched_list);
  622. if(!$searched_count)
  623. {
  624. return;
  625. }
  626. $exceptionModule = array('editor', 'poll', 'homepage', 'textyle');
  627. $oModuleModel = getModel('module');
  628. foreach($searched_list as $val)
  629. {
  630. $skin_list = $oModuleModel->getSkins(_XE_PATH_ . 'modules/' . $val);
  631. if(is_array($skin_list) && count($skin_list) > 0 && !in_array($val, $exceptionModule))
  632. {
  633. if(!$GLOBALS['__ThemeModuleSkin__'][$val])
  634. {
  635. $GLOBALS['__ThemeModuleSkin__'][$val] = array();
  636. $moduleInfo = $oModuleModel->getModuleInfoXml($val);
  637. $GLOBALS['__ThemeModuleSkin__'][$val]['title'] = $moduleInfo->title;
  638. $GLOBALS['__ThemeModuleSkin__'][$val]['skins'] = array();
  639. }
  640. $GLOBALS['__ThemeModuleSkin__'][$val]['skins'] = array_merge($GLOBALS['__ThemeModuleSkin__'][$val]['skins'], $skin_list);
  641. }
  642. }
  643. $GLOBALS['__ThemeModuleSkin__']['__IS_PARSE__'] = TRUE;
  644. return $GLOBALS['__ThemeModuleSkin__'];
  645. }
  646. /**
  647. * Return admin menu language
  648. * @return array
  649. */
  650. function getAdminMenuLang()
  651. {
  652. $currentLang = Context::getLangType();
  653. $cacheFile = sprintf('./files/cache/menu/admin_lang/adminMenu.%s.lang.php', $currentLang);
  654. // Update if no cache file exists or it is older than xml file
  655. if(!is_readable($cacheFile))
  656. {
  657. $lang = new stdClass();
  658. $oModuleModel = getModel('module');
  659. $installed_module_list = $oModuleModel->getModulesXmlInfo();
  660. $this->gnbLangBuffer = '<?php $lang = new stdClass();';
  661. foreach($installed_module_list AS $key => $value)
  662. {
  663. $moduleActionInfo = $oModuleModel->getModuleActionXml($value->module);
  664. if(is_object($moduleActionInfo->menu))
  665. {
  666. foreach($moduleActionInfo->menu AS $key2 => $value2)
  667. {
  668. $lang->menu_gnb_sub[$key2] = $value2->title;
  669. $this->gnbLangBuffer .=sprintf('$lang->menu_gnb_sub[\'%s\'] = \'%s\';', $key2, $value2->title);
  670. }
  671. }
  672. }
  673. $this->gnbLangBuffer .= ' ?>';
  674. FileHandler::writeFile($cacheFile, $this->gnbLangBuffer);
  675. }
  676. else
  677. {
  678. include $cacheFile;
  679. }
  680. return $lang->menu_gnb_sub;
  681. }
  682. /**
  683. * Get admin favorite list
  684. * @param int $siteSrl if default site, siteSrl is zero
  685. * @param bool $isGetModuleInfo
  686. * @return object
  687. */
  688. function getFavoriteList($siteSrl = 0, $isGetModuleInfo = FALSE)
  689. {
  690. $args = new stdClass();
  691. $args->site_srl = $siteSrl;
  692. $output = executeQueryArray('admin.getFavoriteList', $args);
  693. if(!$output->toBool())
  694. {
  695. return $output;
  696. }
  697. if(!$output->data)
  698. {
  699. return new Object();
  700. }
  701. if($isGetModuleInfo && is_array($output->data))
  702. {
  703. $oModuleModel = getModel('module');
  704. foreach($output->data AS $key => $value)
  705. {
  706. $moduleInfo = $oModuleModel->getModuleInfoXml($value->module);
  707. $output->data[$key]->admin_index_act = $moduleInfo->admin_index_act;
  708. $output->data[$key]->title = $moduleInfo->title;
  709. }
  710. }
  711. $returnObject = new Object();
  712. $returnObject->add('favoriteList', $output->data);
  713. return $returnObject;
  714. }
  715. /**
  716. * Check available insert favorite
  717. * @param int $siteSrl if default site, siteSrl is zero
  718. * @param string $module
  719. * @return object
  720. */
  721. function isExistsFavorite($siteSrl, $module)
  722. {
  723. $args = new stdClass();
  724. $args->site_srl = $siteSrl;
  725. $args->module = $module;
  726. $output = executeQuery('admin.getFavorite', $args);
  727. if(!$output->toBool())
  728. {
  729. return $output;
  730. }
  731. $returnObject = new Object();
  732. if($output->data)
  733. {
  734. $returnObject->add('result', TRUE);
  735. $returnObject->add('favoriteSrl', $output->data->admin_favorite_srl);
  736. }
  737. else
  738. {
  739. $returnObject->add('result', FALSE);
  740. }
  741. return $returnObject;
  742. }
  743. /**
  744. * Return site list
  745. * @return void
  746. */
  747. function getSiteAllList()
  748. {
  749. if(Context::get('domain'))
  750. {
  751. $domain = Context::get('domain');
  752. }
  753. $siteList = $this->getAllSitesThatHaveModules($domain);
  754. $this->add('site_list', $siteList);
  755. }
  756. /**
  757. * Returns a list of all sites that contain modules
  758. * For each site domain and site_srl are retrieved
  759. *
  760. * @return array
  761. */
  762. function getAllSitesThatHaveModules($domain = NULL)
  763. {
  764. $args = new stdClass();
  765. if($domain)
  766. {
  767. $args->domain = $domain;
  768. }
  769. $columnList = array('domain', 'site_srl');
  770. $siteList = array();
  771. $output = executeQueryArray('admin.getSiteAllList', $args, $columnList);
  772. if($output->toBool())
  773. {
  774. $siteList = $output->data;
  775. }
  776. $oModuleModel = getModel('module');
  777. foreach($siteList as $key => $value)
  778. {
  779. $args->site_srl = $value->site_srl;
  780. $list = $oModuleModel->getModuleSrlList($args);
  781. if(!is_array($list))
  782. {
  783. $list = array($list);
  784. }
  785. foreach($list as $k => $v)
  786. {
  787. if(!is_dir(_XE_PATH_ . 'modules/' . $v->module))
  788. {
  789. unset($list[$k]);
  790. }
  791. }
  792. if(!count($list))
  793. {
  794. unset($siteList[$key]);
  795. }
  796. }
  797. return $siteList;
  798. }
  799. /**
  800. * Return site count
  801. * @param string $date
  802. * @return int
  803. */
  804. function getSiteCountByDate($date = '')
  805. {
  806. $args = new stdClass();
  807. if($date)
  808. {
  809. $args->regDate = date('Ymd', strtotime($date));
  810. }
  811. $output = executeQuery('admin.getSiteCountByDate', $args);
  812. if(!$output->toBool())
  813. {
  814. return 0;
  815. }
  816. return $output->data->count;
  817. }
  818. function getFaviconUrl()
  819. {
  820. return $this->iconUrlCheck('favicon.ico', 'faviconSample.png');
  821. }
  822. function getMobileIconUrl()
  823. {
  824. return $this->iconUrlCheck('mobicon.png', 'mobiconSample.png');
  825. }
  826. function iconUrlCheck($iconname, $default_icon_name)
  827. {
  828. $file_exsit = FileHandler::readFile(_XE_PATH_ . 'files/attach/xeicon/' . $iconname);
  829. if(!$file_exsit)
  830. {
  831. $icon_url = './modules/admin/tpl/img/' . $default_icon_name;
  832. }
  833. else
  834. {
  835. $icon_url = $db_info->default_url . 'files/attach/xeicon/' . $iconname;
  836. }
  837. return $icon_url;
  838. }
  839. }
  840. /* End of file admin.admin.model.php */
  841. /* Location: ./modules/admin/admin.admin.model.php */