PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/extras/installer-ftp/app/Hdinstaller_Controller.php

http://xoopscube-modules.googlecode.com/
PHP | 393 lines | 161 code | 38 blank | 194 comment | 18 complexity | b3eee9c2a8a4b090e26bc1d78c6ec299 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Hdinstaller_Controller.php
  4. *
  5. * @author {$author}
  6. * @package Hdinstaller
  7. * @version $Id: app.controller.php 695 2009-01-20 13:24:16Z sotarok $
  8. */
  9. /** Application base directory */
  10. define('BASE', dirname(dirname(__FILE__)));
  11. /** include_path setting (adding "/app" and "/lib" directory to include_path) */
  12. $app = BASE . "/app";
  13. $lib = BASE . "/lib";
  14. //ini_set('include_path', implode(PATH_SEPARATOR, array($app, $lib)) . PATH_SEPARATOR . ini_get('include_path'));
  15. ini_set('include_path', implode(PATH_SEPARATOR, array($app, $lib)));
  16. ini_set('max_execution_time', '120');
  17. ini_set('memory_limit', '32M');
  18. /** including application library. */
  19. require_once 'Curaga/Ethna.php';
  20. require_once 'Hdinstaller_Error.php';
  21. require_once 'Hdinstaller_ActionClass.php';
  22. require_once 'Hdinstaller_ActionForm.php';
  23. require_once 'Hdinstaller_ViewClass.php';
  24. require_once 'Hdinstaller_ClassFactory.php';
  25. require_once 'Hdinstaller_Plugin.php';
  26. /**
  27. * Hdinstaller application Controller definition.
  28. *
  29. * @author {$author}
  30. * @access public
  31. * @package Hdinstaller
  32. */
  33. class Hdinstaller_Controller extends Ethna_Controller
  34. {
  35. /**#@+
  36. * @access private
  37. */
  38. /**
  39. * @var string Application ID(appid)
  40. */
  41. var $appid = 'HDINSTALLER';
  42. /**
  43. * @var array forward definition.
  44. */
  45. var $forward = array(
  46. /*
  47. * TODO: write forward definition here.
  48. *
  49. * Example:
  50. *
  51. * 'index' => array(
  52. * 'view_name' => 'Hdinstaller_View_Index',
  53. * ),
  54. */
  55. );
  56. /**
  57. * @var array action definition.
  58. */
  59. var $action = array(
  60. /*
  61. * TODO: write action definition here.
  62. *
  63. * Example:
  64. *
  65. * 'index' => array(),
  66. */
  67. );
  68. /**
  69. * @var array SOAP action definition.
  70. */
  71. var $soap_action = array(
  72. /*
  73. * TODO: write action definition for SOAP application here.
  74. * Example:
  75. *
  76. * 'sample' => array(),
  77. */
  78. );
  79. /**
  80. * @var array application directory.
  81. */
  82. var $directory = array(
  83. 'action' => 'app/action',
  84. 'action_cli' => 'app/action_cli',
  85. 'action_xmlrpc' => 'app/action_xmlrpc',
  86. 'app' => 'app',
  87. 'plugin' => 'app/plugin',
  88. 'bin' => 'bin',
  89. 'etc' => 'etc',
  90. 'filter' => 'app/filter',
  91. 'locale' => 'locale',
  92. 'log' => 'log',
  93. 'plugins' => array('app/plugin/Smarty',),
  94. 'template' => 'template',
  95. 'template_c' => 'tmp',
  96. 'tmp' => 'tmp',
  97. 'view' => 'app/view',
  98. 'www' => 'www',
  99. 'test' => 'app/test',
  100. );
  101. /**
  102. * @var array database access definition.
  103. */
  104. var $db = array(
  105. '' => DB_TYPE_RW,
  106. );
  107. /**
  108. * @var array extention(.php, etc) configuration.
  109. */
  110. var $ext = array(
  111. 'php' => 'php',
  112. 'tpl' => 'php',
  113. );
  114. /**
  115. * @var array class definition.
  116. */
  117. var $class = array(
  118. /*
  119. * TODO: When you override Configuration class, Logger class,
  120. * SQL class, don't forget to change definition as follows!
  121. */
  122. 'class' => 'Hdinstaller_ClassFactory',
  123. 'backend' => 'Ethna_Backend',
  124. 'config' => 'Ethna_Config',
  125. 'db' => 'Ethna_DB_PEAR',
  126. 'error' => 'Ethna_ActionError',
  127. 'form' => 'Hdinstaller_ActionForm',
  128. 'i18n' => 'Ethna_I18N',
  129. 'logger' => 'Ethna_Logger',
  130. 'plugin' => 'Hdinstaller_Plugin',
  131. 'session' => 'Ethna_Session',
  132. 'sql' => 'Ethna_AppSQL',
  133. 'view' => 'Hdinstaller_ViewClass',
  134. // 'renderer' => 'Ethna_Renderer_Smarty',
  135. 'renderer' => 'Hdinstaller_Renderer_Php',
  136. 'url_handler' => 'Hdinstaller_UrlHandler',
  137. );
  138. /**
  139. * @var array list of application id where Ethna searches plugin.
  140. */
  141. var $plugin_search_appids = array(
  142. /*
  143. * write list of application id where Ethna searches plugin.
  144. *
  145. * Example:
  146. * When there are plugins whose name are like "Common_Plugin_Foo_Bar" in
  147. * application plugin directory, Ethna searches them in the following order.
  148. *
  149. * 1. Common_Plugin_Foo_Bar,
  150. * 2. Hdinstaller_Plugin_Foo_Bar
  151. * 3. Ethna_Plugin_Foo_Bar
  152. *
  153. * 'Common', 'Hdinstaller', 'Ethna',
  154. */
  155. 'Hdinstaller', 'Ethna',
  156. );
  157. /**
  158. * @var array filter definition.
  159. */
  160. var $filter = array(
  161. /*
  162. * TODO: when you use filter, write filter plugin name here.
  163. * (If you specify class name, Ethna reads filter class in
  164. * filter directory)
  165. *
  166. * Example:
  167. *
  168. * 'ExecutionTime',
  169. */
  170. );
  171. /**
  172. * @var array smarty modifier definition.
  173. */
  174. var $smarty_modifier_plugin = array(
  175. /*
  176. * TODO: write user defined smarty modifier here.
  177. *
  178. * Example:
  179. *
  180. * 'smarty_modifier_foo_bar',
  181. */
  182. );
  183. /**
  184. * @var array smarty function definition.
  185. */
  186. var $smarty_function_plugin = array(
  187. /*
  188. * TODO: write user defined smarty function here.
  189. *
  190. * Example:
  191. *
  192. * 'smarty_function_foo_bar',
  193. */
  194. );
  195. /**
  196. * @var array smarty block definition.
  197. */
  198. var $smarty_block_plugin = array(
  199. /*
  200. * TODO: write user defined smarty block here.
  201. *
  202. * Example:
  203. *
  204. * 'smarty_block_foo_bar',
  205. */
  206. );
  207. /**
  208. * @var array smarty prefilter definition.
  209. */
  210. var $smarty_prefilter_plugin = array(
  211. /*
  212. * TODO: write user defined smarty prefilter here.
  213. *
  214. * Example:
  215. *
  216. * 'smarty_prefilter_foo_bar',
  217. */
  218. );
  219. /**
  220. * @var array smarty postfilter definition.
  221. */
  222. var $smarty_postfilter_plugin = array(
  223. /*
  224. * TODO: write user defined smarty postfilter here.
  225. *
  226. * Example:
  227. *
  228. * 'smarty_postfilter_foo_bar',
  229. */
  230. );
  231. /**
  232. * @var array smarty outputfilter definition.
  233. */
  234. var $smarty_outputfilter_plugin = array(
  235. /*
  236. * TODO: write user defined smarty outputfilter here.
  237. *
  238. * Example:
  239. *
  240. * 'smarty_outputfilter_foo_bar',
  241. */
  242. );
  243. /**#@-*/
  244. /**
  245. * Get Default language and locale setting.
  246. * If you want to change Ethna's output encoding, override this method.
  247. *
  248. * @access protected
  249. * @return array locale name(e.x ja_JP, en_US .etc),
  250. * system encoding name,
  251. * client encoding name(= template encoding)
  252. * (locale name is "ll_cc" format. ll = language code. cc = country code.)
  253. */
  254. function _getDefaultLanguage()
  255. {
  256. $config = $this->getConfig();
  257. $allow_language = $config->get('allow_language');
  258. $lang = null;
  259. if (strcasecmp($_SERVER['REQUEST_METHOD'], 'get')===0){
  260. $lang = isset($_GET['lang']) ? $_GET['lang'] : null;
  261. }
  262. if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post')===0){
  263. $lang = isset($_POST['lang']) ? $_POST['lang'] : null;
  264. }
  265. if ($lang){
  266. foreach ($allow_language as $s=>$l){
  267. if ($l['lang'] === $lang){
  268. return array($lang, 'UTF-8', 'UTF-8');
  269. }
  270. }
  271. }
  272. $lang = 'en_US';
  273. $accept = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  274. $a_langs = explode(',', $accept[0]);
  275. foreach ($a_langs as $al){
  276. foreach ($allow_language as $s=>$l){
  277. if (strncasecmp($l['lang'], $al, 2)===0){
  278. $lang = $l['lang'];
  279. return array($lang, 'UTF-8', 'UTF-8');
  280. }
  281. }
  282. }
  283. return array($lang, 'UTF-8', 'UTF-8');
  284. }
  285. /// Locale?????
  286. function getTemplatedir()
  287. {
  288. $template = $this->getDirectory('template');
  289. // ?????????
  290. // _getDerfaultLanguage?????????????????????
  291. // ??????????????????????????
  292. if (!empty($this->locale)) {
  293. // $template .= '/' . $this->locale;
  294. }
  295. return $template;
  296. }
  297. /// Repository URL?Cache???????
  298. /**
  299. * @brief
  300. * @param
  301. * @retval
  302. */
  303. function repositoryURL2CacheFile($url)
  304. {
  305. $url = parse_url($url);
  306. $ret = sprintf('%s_%s_%s',
  307. $url['scheme'],
  308. $url['host'],
  309. str_replace(array('/', '_'), array('%', '.'), $url['path'])
  310. );
  311. if (isset($url['query']) && $url['query']){
  312. $ret .= '_'.md5($url['query']);
  313. }
  314. return BASE.'/tmp/'.$ret;
  315. }
  316. ///
  317. /**
  318. * @brief
  319. * @param
  320. * @retval
  321. */
  322. function package2dataFile($package, $version)
  323. {
  324. $filename = urlencode($package). urlencode($version);
  325. return sprintf('%s/%s', BASE.'/tmp', $filename);
  326. }
  327. /// Tmp????????????
  328. /**
  329. * @brief
  330. * @param
  331. * @retval
  332. */
  333. function cleanUpTmp($dir='')
  334. {
  335. if (!$dir) $dir = $this->getDirectory('tmp');
  336. $dh = opendir($dir);
  337. if ($dh) {
  338. while (($file = readdir($dh)) !== false) {
  339. if ($file == '.' || $file == '..') {
  340. continue;
  341. }
  342. else if (is_dir($dir . '/' . $file)) {
  343. $this->cleanUpTmp($dir . '/' . $file);
  344. rmdir($dir . '/' . $file);
  345. }
  346. else {
  347. $f = $dir . "/" . $file;
  348. unlink($f);
  349. }
  350. }
  351. closedir($dh);
  352. }
  353. }
  354. }
  355. ?>