PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/extras/installer-ftp/lib/Curaga/class/Ethna_Controller.php

http://xoopscube-modules.googlecode.com/
PHP | 2212 lines | 1123 code | 244 blank | 845 comment | 224 complexity | 1eece36e5866764e1feac81ff40a5825 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4. * Ethna_Controller.php
  5. *
  6. * @author Masaki Fujimoto <fujimoto@php.net>
  7. * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  8. * @package Ethna
  9. * @version $Id: Ethna_Controller.php 866 2009-06-17 17:01:20Z mumumu-org $
  10. */
  11. // {{{ Ethna_Controller
  12. /**
  13. * ?????????
  14. *
  15. * @todo gateway?switch???????????
  16. *
  17. * @author Masaki Fujimoto <fujimoto@php.net>
  18. * @access public
  19. * @package Ethna
  20. */
  21. class Ethna_Controller
  22. {
  23. /**#@+
  24. * @access private
  25. */
  26. /** @var string ????????ID */
  27. var $appid = 'ETHNA';
  28. /** @var string ????????????????? */
  29. var $base = '';
  30. /** @var string ???????????URL */
  31. var $url = '';
  32. /** @var string ????????DSN(Data Source Name) */
  33. var $dsn;
  34. /** @var array ?????????????? */
  35. var $directory = array();
  36. /** @var array ??????????????(?????) */
  37. var $directory_default = array(
  38. 'action' => 'app/action',
  39. 'action_cli' => 'app/action_cli',
  40. 'action_xmlrpc' => 'app/action_xmlrpc',
  41. 'app' => 'app',
  42. 'plugin' => 'app/plugin',
  43. 'bin' => 'bin',
  44. 'etc' => 'etc',
  45. 'filter' => 'app/filter',
  46. 'locale' => 'locale',
  47. 'log' => 'log',
  48. 'plugins' => array(),
  49. 'template' => 'template',
  50. 'template_c' => 'tmp',
  51. 'tmp' => 'tmp',
  52. 'view' => 'app/view',
  53. 'www' => 'www',
  54. 'test' => 'app/test',
  55. );
  56. /** @var array DB?????? */
  57. var $db = array(
  58. '' => DB_TYPE_RW,
  59. );
  60. /** @var array ????? */
  61. var $ext = array(
  62. 'php' => 'php',
  63. 'tpl' => 'tpl',
  64. );
  65. /** @var array ????? */
  66. var $class = array();
  67. /** @var array ?????(?????) */
  68. var $class_default = array(
  69. 'class' => 'Ethna_ClassFactory',
  70. 'backend' => 'Ethna_Backend',
  71. 'config' => 'Ethna_Config',
  72. 'db' => 'Ethna_DB',
  73. 'error' => 'Ethna_ActionError',
  74. 'form' => 'Ethna_ActionForm',
  75. 'i18n' => 'Ethna_I18N',
  76. 'logger' => 'Ethna_Logger',
  77. 'plugin' => 'Ethna_Plugin',
  78. 'renderer' => 'Ethna_Renderer_Smarty',
  79. 'session' => 'Ethna_Session',
  80. 'sql' => 'Ethna_AppSQL',
  81. 'view' => 'Ethna_ViewClass',
  82. 'url_handler' => 'Ethna_UrlHandler',
  83. );
  84. /** @var array ?????? */
  85. var $filter = array(
  86. );
  87. /** @var string ???????? */
  88. var $locale;
  89. /** @var string ????????????? */
  90. var $system_encoding;
  91. /** @var string ??????????????? */
  92. /** ?????????????????? */
  93. var $client_encoding;
  94. /** @var string ???????????? */
  95. var $action_name;
  96. /** @var string ??????XMLRPC????? */
  97. var $xmlrpc_method_name;
  98. /** @var array forward?? */
  99. var $forward = array();
  100. /** @var array ??????forward?? */
  101. var $forward_default = array(
  102. '403' => array( 'view_name' => 'Ethna_View_403',),
  103. '404' => array( 'view_name' => 'Ethna_View_404',),
  104. '500' => array( 'view_name' => 'Ethna_View_500',),
  105. 'json' => array( 'view_name' => 'Ethna_View_Json',),
  106. 'redirect' => array( 'view_name' => 'Ethna_View_Redirect',),
  107. );
  108. /** @var array action?? */
  109. var $action = array();
  110. /** @var array action(CLI)?? */
  111. var $action_cli = array();
  112. /** @var array action(XMLRPC)?? */
  113. var $action_xmlrpc = array();
  114. /** @var array ??????????????? */
  115. var $manager = array();
  116. /** @var object ????? */
  117. var $renderer = null;
  118. /** @var array ?????????(Ethna_Filter?????????) */
  119. var $filter_chain = array();
  120. /** @var object Ethna_ClassFactory ?????????????? */
  121. var $class_factory = null;
  122. /** @var object Ethna_ActionForm ?????????? */
  123. var $action_form = null;
  124. /** @var object Ethna_View ????????? */
  125. var $view = null;
  126. /** @var object Ethna_Config ???????? */
  127. var $config = null;
  128. /** @var object Ethna_Logger ???????? */
  129. var $logger = null;
  130. /** @var object Ethna_Plugin ??????????? */
  131. var $plugin = null;
  132. /** @var string ????????????(www/cli/rest/xmlrpc/soap...) */
  133. var $gateway = GATEWAY_WWW;
  134. /**#@-*/
  135. /**
  136. * Ethna_Controller???????????
  137. *
  138. * @access public
  139. */
  140. function Ethna_Controller($gateway = GATEWAY_WWW)
  141. {
  142. $GLOBALS['_Ethna_controller'] =& $this;
  143. if ($this->base === "") {
  144. // Ethna???????BASE??????????????
  145. if (defined('BASE')) {
  146. $this->base = BASE;
  147. }
  148. }
  149. $this->gateway = $gateway;
  150. // ?????????????
  151. foreach ($this->class_default as $key => $val) {
  152. if (isset($this->class[$key]) == false) {
  153. $this->class[$key] = $val;
  154. }
  155. }
  156. // ????????????????
  157. foreach ($this->directory_default as $key => $val) {
  158. if (isset($this->directory[$key]) == false) {
  159. $this->directory[$key] = $val;
  160. }
  161. }
  162. // ?????????????????
  163. $class_factory = $this->class['class'];
  164. $this->class_factory =& new $class_factory($this, $this->class);
  165. // ??????????
  166. Ethna::setErrorCallback(array(&$this, 'handleError'));
  167. // ??????????(????->????)
  168. foreach ($this->directory as $key => $value) {
  169. if ($key == 'plugins') {
  170. // Smarty???????????????????
  171. $tmp = array();
  172. foreach (to_array($value) as $elt) {
  173. if (Ethna_Util::isAbsolute($elt) == false) {
  174. $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt;
  175. }
  176. }
  177. $this->directory[$key] = $tmp;
  178. } else {
  179. if (Ethna_Util::isAbsolute($value) == false) {
  180. $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value;
  181. }
  182. }
  183. }
  184. // ?????????
  185. // ?????????????
  186. $this->forward = $this->forward + $this->forward_default;
  187. // ????
  188. // ????????????????????????????
  189. // ?????????=???????????????)
  190. //
  191. // @see Ethna_Controller#_getDefaultLanguage
  192. list($this->locale, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage();
  193. if (mb_enabled()) {
  194. mb_internal_encoding($this->client_encoding);
  195. mb_regex_encoding($this->client_encoding);
  196. }
  197. $this->config =& $this->getConfig();
  198. $this->dsn = $this->_prepareDSN();
  199. $this->url = $this->config->get('url');
  200. // ??????????????
  201. $this->plugin =& $this->getPlugin();
  202. //// assert (experimental)
  203. //if ($this->config->get('debug') === false) {
  204. // ini_set('assert.active', 0);
  205. //}
  206. // ??????
  207. $this->logger =& $this->getLogger();
  208. $this->plugin->setLogger($this->logger);
  209. $this->logger->begin();
  210. // Ethna???????
  211. $this->_activateEthnaManager();
  212. }
  213. /**
  214. * ?????????????????????
  215. *
  216. * @access protected
  217. */
  218. function end()
  219. {
  220. // ??????????????????
  221. $this->logger->end();
  222. }
  223. /**
  224. * (????????)????????????????
  225. *
  226. * @access public
  227. * @return object Ethna_Controller ?????????????
  228. * @static
  229. */
  230. function &getInstance()
  231. {
  232. if (isset($GLOBALS['_Ethna_controller'])) {
  233. return $GLOBALS['_Ethna_controller'];
  234. } else {
  235. $_ret_object = null;
  236. return $_ret_object;
  237. }
  238. }
  239. /**
  240. * ????????ID???
  241. *
  242. * @access public
  243. * @return string ????????ID
  244. */
  245. function getAppId()
  246. {
  247. return ucfirst(strtolower($this->appid));
  248. }
  249. /**
  250. * ????????ID???????
  251. *
  252. * @access public
  253. * @param string $id ????????ID
  254. * @return mixed true:OK Ethna_Error:NG
  255. * @static
  256. */
  257. function &checkAppId($id)
  258. {
  259. $true = true;
  260. if (strcasecmp($id, 'ethna') === 0
  261. || strcasecmp($id, 'app') === 0) {
  262. return Ethna::raiseError("Application Id [$id] is reserved\n");
  263. }
  264. // ????????ID??????prefix???????
  265. // ??????????????
  266. // @see http://www.php.net/manual/en/language.variables.php
  267. if (preg_match('/^[a-zA-Z][a-zA-Z0-9]*$/', $id) === 0) {
  268. $msg = (preg_match('/^[0-9]$/', $id[0]))
  269. ? "Application ID must NOT start with Number.\n"
  270. : "Only Numeric(0-9) and Alphabetical(A-Z) is allowed for Application Id\n";
  271. return Ethna::raiseError($msg);
  272. }
  273. return $true;
  274. }
  275. /**
  276. * ?????????????
  277. *
  278. * @access public
  279. * @param string $action_name ??????
  280. * @return mixed true:OK Ethna_Error:NG
  281. * @static
  282. */
  283. function &checkActionName($action_name)
  284. {
  285. $true = true;
  286. if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
  287. $action_name) === 0) {
  288. return Ethna::raiseError("invalid action name [$action_name]");
  289. }
  290. return $true;
  291. }
  292. /**
  293. * ???????????
  294. *
  295. * @access public
  296. * @param string $view_name ????
  297. * @return mixed true:OK Ethna_Error:NG
  298. * @static
  299. */
  300. function &checkViewName($view_name)
  301. {
  302. $true = true;
  303. if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
  304. $view_name) === 0) {
  305. return Ethna::raiseError("invalid view name [$view_name]");
  306. }
  307. return $true;
  308. }
  309. /**
  310. * DSN???
  311. *
  312. * @access public
  313. * @param string $db_key DB??
  314. * @return string DSN
  315. */
  316. function getDSN($db_key = "")
  317. {
  318. if (isset($this->dsn[$db_key]) == false) {
  319. return null;
  320. }
  321. return $this->dsn[$db_key];
  322. }
  323. /**
  324. * DSN??????????
  325. *
  326. * @access public
  327. * @param string $db_key DB??
  328. * @return bool true:persistent false:non-persistent(????????)
  329. */
  330. function getDSN_persistent($db_key = "")
  331. {
  332. $key = sprintf("dsn%s_persistent", $db_key == "" ? "" : "_$db_key");
  333. $dsn_persistent = $this->config->get($key);
  334. if (is_null($dsn_persistent)) {
  335. return false;
  336. }
  337. return $dsn_persistent;
  338. }
  339. /**
  340. * DB?????
  341. *
  342. * @access public
  343. * @param string $db_key DB??("", "r", "rw", "default", "blog_r"...)
  344. * @return string $db_key?????DB????(????????null)
  345. */
  346. function getDBType($db_key = null)
  347. {
  348. if (is_null($db_key)) {
  349. // ?????
  350. return $this->db;
  351. }
  352. if (isset($this->db[$db_key]) == false) {
  353. return null;
  354. }
  355. return $this->db[$db_key];
  356. }
  357. /**
  358. * ???????????URL???
  359. *
  360. * @access public
  361. * @return string ???????????URL
  362. */
  363. function getURL()
  364. {
  365. return $this->url;
  366. }
  367. /**
  368. * ????????????????????
  369. *
  370. * @access public
  371. * @return string ?????????????????
  372. */
  373. function getBasedir()
  374. {
  375. return $this->base;
  376. }
  377. /**
  378. * ?????????/??????????????????????
  379. * ??????? [appid]/template/ja_JP/ (ja_JP??????)
  380. * ?????? _getDefaultLanguage ???????
  381. *
  382. * @access public
  383. * @return string ????????????
  384. * @see Ethna_Controller#_getDefaultLanguage
  385. */
  386. function getTemplatedir()
  387. {
  388. $template = $this->getDirectory('template');
  389. // ?????????
  390. // _getDerfaultLanguage?????????????????????
  391. // ??????????????????????????
  392. if (!empty($this->locale)) {
  393. $template .= '/' . $this->locale;
  394. }
  395. return $template;
  396. }
  397. /**
  398. * ?????????????????
  399. *
  400. * @access public
  401. * @return string ???????????
  402. */
  403. function getActiondir($gateway = null)
  404. {
  405. $key = 'action';
  406. $gateway = is_null($gateway) ? $this->getGateway() : $gateway;
  407. switch ($gateway) {
  408. case GATEWAY_WWW:
  409. $key = 'action';
  410. break;
  411. case GATEWAY_CLI:
  412. $key = 'action_cli';
  413. break;
  414. case GATEWAY_XMLRPC:
  415. $key = 'action_xmlrpc';
  416. break;
  417. }
  418. return (empty($this->directory[$key]) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory[$key] . "/"));
  419. }
  420. /**
  421. * ???????????????
  422. *
  423. * @access public
  424. * @return string ?????????
  425. */
  426. function getViewdir()
  427. {
  428. return (empty($this->directory['view']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['view'] . "/"));
  429. }
  430. /**
  431. * (action,view???)?????????????????????
  432. *
  433. * @access public
  434. * @return string ???????????????
  435. */
  436. function getTestdir()
  437. {
  438. return (empty($this->directory['test']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['test'] . "/"));
  439. }
  440. /**
  441. * ???????????????????
  442. *
  443. * @access public
  444. * @param string $key ?????????("tmp", "template"...)
  445. * @return string $key???????????????????(????????null)
  446. */
  447. function getDirectory($key)
  448. {
  449. if (isset($this->directory[$key]) == false) {
  450. return null;
  451. }
  452. return $this->directory[$key];
  453. }
  454. /**
  455. * ????????????????
  456. *
  457. * @access public
  458. * @param string $key ??????("php", "tpl"...)
  459. * @return string $key????????(????????null)
  460. */
  461. function getExt($key)
  462. {
  463. if (isset($this->ext[$key]) == false) {
  464. return null;
  465. }
  466. return $this->ext[$key];
  467. }
  468. /**
  469. * ???????????????????(R)
  470. *
  471. * @access public
  472. * @return object Ethna_ClassFactory ??????????????
  473. */
  474. function &getClassFactory()
  475. {
  476. return $this->class_factory;
  477. }
  478. /**
  479. * ???????????????????
  480. *
  481. * @access public
  482. * @return object Ethna_ActionError ??????????????
  483. */
  484. function &getActionError()
  485. {
  486. return $this->class_factory->getObject('error');
  487. }
  488. /**
  489. * ????????????????????
  490. *
  491. * @access public
  492. * @return object Ethna_ActionForm ???????????????
  493. */
  494. function &getActionForm()
  495. {
  496. // ????????????????????
  497. return $this->action_form;
  498. }
  499. /**
  500. * ??????????????
  501. *
  502. * @access public
  503. * @return object Ethna_View ?????????
  504. */
  505. function &getView()
  506. {
  507. // ????????????????????
  508. return $this->view;
  509. }
  510. /**
  511. * backend???????????
  512. *
  513. * @access public
  514. * @return object Ethna_Backend backend??????
  515. */
  516. function &getBackend()
  517. {
  518. return $this->class_factory->getObject('backend');
  519. }
  520. /**
  521. * ?????????????
  522. *
  523. * @access public
  524. * @return object Ethna_Config ????????
  525. */
  526. function &getConfig()
  527. {
  528. return $this->class_factory->getObject('config');
  529. }
  530. /**
  531. * i18n???????????(R)
  532. *
  533. * @access public
  534. * @return object Ethna_I18N i18n??????
  535. */
  536. function &getI18N()
  537. {
  538. return $this->class_factory->getObject('i18n');
  539. }
  540. /**
  541. * ?????????????
  542. *
  543. * @access public
  544. * @return object Ethna_Logger ????????
  545. */
  546. function &getLogger()
  547. {
  548. return $this->class_factory->getObject('logger');
  549. }
  550. /**
  551. * ????????????????
  552. *
  553. * @access public
  554. * @return object Ethna_Session ???????????
  555. */
  556. function &getSession()
  557. {
  558. return $this->class_factory->getObject('session');
  559. }
  560. /**
  561. * SQL???????????
  562. *
  563. * @access public
  564. * @return object Ethna_AppSQL SQL??????
  565. */
  566. function &getSQL()
  567. {
  568. return $this->class_factory->getObject('sql');
  569. }
  570. /**
  571. * ????????????????
  572. *
  573. * @access public
  574. * @return object Ethna_Plugin ???????????
  575. */
  576. function &getPlugin()
  577. {
  578. return $this->class_factory->getObject('plugin');
  579. }
  580. /**
  581. * URL???????????????
  582. *
  583. * @access public
  584. * @return object Ethna_UrlHandler URL??????????
  585. */
  586. function &getUrlHandler()
  587. {
  588. return $this->class_factory->getObject('url_handler');
  589. }
  590. /**
  591. * ??????????
  592. *
  593. * @access public
  594. * @return array ???????
  595. * @obsolete
  596. */
  597. function getManagerList()
  598. {
  599. return $this->manager;
  600. }
  601. /**
  602. * ?????????????
  603. *
  604. * @access public
  605. * @return string ??????????
  606. */
  607. function getCurrentActionName()
  608. {
  609. return $this->action_name;
  610. }
  611. /**
  612. * ????XMLRPC????????
  613. *
  614. * @access public
  615. * @return string ????XMLRPC?????
  616. */
  617. function getXmlrpcMethodName()
  618. {
  619. return $this->xmlrpc_method_name;
  620. }
  621. /**
  622. * ????????????????
  623. *
  624. * @access public
  625. * @return array ?????(e.x ja_JP, en_US ?),
  626. * ?????????????,
  627. * ??????????????? ???
  628. * (???????ll_cc ????ll = ????? cc = ????)
  629. * @see http://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html
  630. */
  631. function getLanguage()
  632. {
  633. return array($this->locale, $this->system_encoding, $this->client_encoding);
  634. }
  635. /**
  636. * ???????????(R)
  637. *
  638. * @access public
  639. * @return string ?????(e.x ja_JP, en_US ?),
  640. * (???????ll_cc ????ll = ????? cc = ????)
  641. */
  642. function getLocale()
  643. {
  644. return $this->locale;
  645. }
  646. /**
  647. * ???????????(W)
  648. *
  649. * @access public
  650. * @param $locale ?????(e.x ja_JP, en_US ?),
  651. * (???????ll_cc ????ll = ????? cc = ????)
  652. */
  653. function setLocale($locale)
  654. {
  655. $this->locale = $locale;
  656. $i18n =& $this->getI18N();
  657. $i18n->setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
  658. }
  659. /**
  660. * ?????????????????????(R)
  661. *
  662. * @access public
  663. * @return string $client_encoding ???????????????
  664. */
  665. function getClientEncoding()
  666. {
  667. return $this->client_encoding;
  668. }
  669. /**
  670. * ?????????????????????(W)
  671. *
  672. * @access public
  673. * @param string $client_encoding ???????????????
  674. */
  675. function setClientEncoding($client_encoding)
  676. {
  677. $this->client_encoding = $client_encoding;
  678. $i18n =& $this->getI18N();
  679. $i18n->setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
  680. }
  681. /**
  682. * ???????????
  683. *
  684. * @access public
  685. */
  686. function getGateway()
  687. {
  688. return $this->gateway;
  689. }
  690. /**
  691. * ??????????????
  692. *
  693. * @access public
  694. */
  695. function setGateway($gateway)
  696. {
  697. $this->gateway = $gateway;
  698. }
  699. /**
  700. * ?????????????????
  701. *
  702. * @access public
  703. * @param string $class_name ???????????????????
  704. * @param mixed $action_name ?????????(???)
  705. * @param mixed $fallback_action_name ????????????????????????????(???)
  706. * @static
  707. */
  708. function main($class_name, $action_name = "", $fallback_action_name = "")
  709. {
  710. $c =& new $class_name;
  711. $c->trigger($action_name, $fallback_action_name);
  712. $c->end();
  713. }
  714. /**
  715. * CLI?????????????????
  716. *
  717. * @access public
  718. * @param string $class_name ???????????????????
  719. * @param string $action_name ??????????
  720. * @param bool $enable_filter ??????????????????
  721. * @static
  722. */
  723. function main_CLI($class_name, $action_name, $enable_filter = true)
  724. {
  725. $c =& new $class_name(GATEWAY_CLI);
  726. $c->action_cli[$action_name] = array();
  727. $c->trigger($action_name, "", $enable_filter);
  728. $c->end();
  729. }
  730. /**
  731. * XMLRPC?????????????????
  732. *
  733. * @access public
  734. * @static
  735. */
  736. function main_XMLRPC($class_name)
  737. {
  738. if (extension_loaded('xmlrpc') == false) {
  739. die("xmlrpc extension is required to enable this gateway");
  740. }
  741. $c =& new $class_name(GATEWAY_XMLRPC);
  742. $c->trigger("", "", false);
  743. $c->end();
  744. }
  745. /**
  746. * SOAP?????????????????
  747. *
  748. * @access public
  749. * @param string $class_name ???????????????????
  750. * @param mixed $action_name ?????????(???)
  751. * @param mixed $fallback_action_name ????????????????????????????(???)
  752. * @static
  753. */
  754. function main_SOAP($class_name, $action_name = "", $fallback_action_name = "")
  755. {
  756. $c =& new $class_name(GATEWAY_SOAP);
  757. $c->trigger($action_name, $fallback_action_name);
  758. $c->end();
  759. }
  760. /**
  761. * ???????????????
  762. *
  763. * @access public
  764. * @param mixed $default_action_name ?????????
  765. * @param mixed $fallback_action_name ?????????????????????????????
  766. * @param bool $enable_filter ??????????????????
  767. * @return mixed 0:???? Ethna_Error:???
  768. */
  769. function trigger($default_action_name = "", $fallback_action_name = "", $enable_filter = true)
  770. {
  771. // ????????
  772. if ($enable_filter) {
  773. $this->_createFilterChain();
  774. }
  775. // ???????
  776. for ($i = 0; $i < count($this->filter_chain); $i++) {
  777. $r = $this->filter_chain[$i]->preFilter();
  778. if (Ethna::isError($r)) {
  779. return $r;
  780. }
  781. }
  782. // trigger
  783. switch ($this->getGateway()) {
  784. case GATEWAY_WWW:
  785. $this->_trigger_WWW($default_action_name, $fallback_action_name);
  786. break;
  787. case GATEWAY_CLI:
  788. $this->_trigger_CLI($default_action_name);
  789. break;
  790. case GATEWAY_XMLRPC:
  791. $this->_trigger_XMLRPC();
  792. break;
  793. case GATEWAY_SOAP:
  794. $this->_trigger_SOAP();
  795. break;
  796. }
  797. // ???????
  798. for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
  799. $r = $this->filter_chain[$i]->postFilter();
  800. if (Ethna::isError($r)) {
  801. return $r;
  802. }
  803. }
  804. }
  805. /**
  806. * ???????????????(WWW)
  807. *
  808. * ??$default_action_name??????????????????????
  809. * ??????????????(???????????????????
  810. * ?????????????????????????)
  811. *
  812. * @access private
  813. * @param mixed $default_action_name ?????????
  814. * @param mixed $fallback_action_name ?????????????????????????????
  815. * @return mixed 0:???? Ethna_Error:???
  816. */
  817. function _trigger_WWW($default_action_name = "", $fallback_action_name = "")
  818. {
  819. // ?????????
  820. $action_name = $this->_getActionName($default_action_name, $fallback_action_name);
  821. // ???????????
  822. $this->_ethnaManagerEnabledCheck($action_name);
  823. // ??????????
  824. $action_obj =& $this->_getAction($action_name);
  825. if (is_null($action_obj)) {
  826. if ($fallback_action_name != "") {
  827. $this->logger->log(LOG_DEBUG, 'undefined action [%s] -> try fallback action [%s]', $action_name, $fallback_action_name);
  828. $action_obj =& $this->_getAction($fallback_action_name);
  829. }
  830. if (is_null($action_obj)) {
  831. return Ethna::raiseError("undefined action [%s]", E_APP_UNDEFINED_ACTION, $action_name);
  832. } else {
  833. $action_name = $fallback_action_name;
  834. }
  835. }
  836. // ????????????
  837. for ($i = 0; $i < count($this->filter_chain); $i++) {
  838. $r = $this->filter_chain[$i]->preActionFilter($action_name);
  839. if ($r != null) {
  840. $this->logger->log(LOG_DEBUG, 'action [%s] -> [%s] by %s', $action_name, $r, get_class($this->filter_chain[$i]));
  841. $action_name = $r;
  842. }
  843. }
  844. $this->action_name = $action_name;
  845. // ????????
  846. $backend =& $this->getBackend();
  847. $session =& $this->getSession();
  848. $session->restore();
  849. // ????????????
  850. $this->_setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
  851. // ????????????
  852. // ??????????????
  853. $form_name = $this->getActionFormName($action_name);
  854. $this->action_form =& new $form_name($this);
  855. $this->action_form->setFormDef_PreHelper();
  856. $this->action_form->setFormVars();
  857. $backend->setActionForm($this->action_form);
  858. // ??????????
  859. $forward_name = $backend->perform($action_name);
  860. // ????????????
  861. for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
  862. $r = $this->filter_chain[$i]->postActionFilter($action_name, $forward_name);
  863. if ($r != null) {
  864. $this->logger->log(LOG_DEBUG, 'forward [%s] -> [%s] by %s', $forward_name, $r, get_class($this->filter_chain[$i]));
  865. $forward_name = $r;
  866. }
  867. }
  868. // ???????????????(?????)
  869. $forward_name_params = $this->_sortForward($action_name, $forward_name);
  870. // View????????????
  871. $preforward_params = array();
  872. if (is_array($forward_name_params)) {
  873. $forward_name = array_shift($forward_name_params);
  874. $preforward_params = $forward_name_params;
  875. }
  876. else {
  877. $forward_name = $forward_name_params;
  878. }
  879. if ($forward_name != null) {
  880. $view_class_name = $this->getViewClassName($forward_name);
  881. $this->view =& new $view_class_name($backend, $forward_name, $this->_getForwardPath($forward_name));
  882. call_user_func_array(array($this->view, 'preforward'), $preforward_params);
  883. $this->view->forward();
  884. }
  885. return 0;
  886. }
  887. /**
  888. * ???????????????(CLI)
  889. *
  890. * @access private
  891. * @param mixed $default_action_name ?????????
  892. * @return mixed 0:???? Ethna_Error:???
  893. */
  894. function _trigger_CLI($default_action_name = "")
  895. {
  896. return $this->_trigger_WWW($default_action_name);
  897. }
  898. /**
  899. * ???????????????(XMLRPC)
  900. *
  901. * @access private
  902. * @param mixed $action_name ?????????
  903. * @return mixed 0:???? Ethna_Error:???
  904. */
  905. function _trigger_XMLRPC($action_name = "")
  906. {
  907. // prepare xmlrpc server
  908. $xmlrpc_gateway_method_name = "_Ethna_XmlrpcGateway";
  909. $xmlrpc_server = xmlrpc_server_create();
  910. $method = null;
  911. $param = xmlrpc_decode_request(file_get_contents('php://input'), $method);
  912. $this->xmlrpc_method_name = $method;
  913. $request = xmlrpc_encode_request(
  914. $xmlrpc_gateway_method_name,
  915. $param,
  916. array(
  917. 'output_type' => 'xml',
  918. 'verbosity' => 'pretty',
  919. 'escaping' => array('markup'),
  920. 'version' => 'xmlrpc',
  921. 'encoding' => 'utf-8'
  922. )
  923. );
  924. xmlrpc_server_register_method(
  925. $xmlrpc_server,
  926. $xmlrpc_gateway_method_name,
  927. $xmlrpc_gateway_method_name
  928. );
  929. // send request
  930. $r = xmlrpc_server_call_method(
  931. $xmlrpc_server,
  932. $request,
  933. null,
  934. array(
  935. 'output_type' => 'xml',
  936. 'verbosity' => 'pretty',
  937. 'escaping' => array('markup'),
  938. 'version' => 'xmlrpc',
  939. 'encoding' => 'utf-8'
  940. )
  941. );
  942. header('Content-Length: ' . strlen($r));
  943. header('Content-Type: text/xml; charset=UTF-8');
  944. print $r;
  945. }
  946. /**
  947. * _trigger_XMLRPC???????????
  948. *
  949. * @access public
  950. */
  951. function trigger_XMLRPC($method, $param)
  952. {
  953. // ??????????
  954. $action_obj =& $this->_getAction($method);
  955. if (is_null($action_obj)) {
  956. return Ethna::raiseError("undefined xmlrpc method [%s]", E_APP_UNDEFINED_ACTION, $method);
  957. }
  958. // ????????
  959. $backend =& $this->getBackend();
  960. $form_name = $this->getActionFormName($method);
  961. $this->action_form =& new $form_name($this);
  962. $def = $this->action_form->getDef();
  963. $n = 0;
  964. foreach ($def as $key => $value) {
  965. if (isset($param[$n]) == false) {
  966. $this->action_form->set($key, null);
  967. } else {
  968. $this->action_form->set($key, $param[$n]);
  969. }
  970. $n++;
  971. }
  972. // ??????????
  973. $backend->setActionForm($this->action_form);
  974. $session =& $this->getSession();
  975. $session->restore();
  976. $r = $backend->perform($method);
  977. return $r;
  978. }
  979. /**
  980. * SOAP???????????????
  981. *
  982. * @access private
  983. */
  984. function _trigger_SOAP()
  985. {
  986. // SOAP???????
  987. $gg =& new Ethna_SOAP_GatewayGenerator();
  988. $script = $gg->generate();
  989. eval($script);
  990. // SOAP???????
  991. $server =& new SoapServer(null, array('uri' => $this->config->get('url')));
  992. $server->setClass($gg->getClassName());
  993. $server->handle();
  994. }
  995. /**
  996. * ???????
  997. *
  998. * ???????????????????????????????????
  999. * (???????????????????????????????
  1000. * ??????????????????????????????
  1001. * ????????)
  1002. *
  1003. * @access public
  1004. * @param object Ethna_Error ?????????
  1005. */
  1006. function handleError(&$error)
  1007. {
  1008. // ????
  1009. list ($log_level, $dummy) = $this->logger->errorLevelToLogLevel($error->getLevel());
  1010. $message = $error->getMessage();
  1011. $this->logger->log($log_level, sprintf("%s [ERROR CODE(%d)]", $message, $error->getCode()));
  1012. }
  1013. /**
  1014. * ?????????????
  1015. *
  1016. * @access public
  1017. * @param int $code ??????
  1018. * @return string ????????
  1019. */
  1020. function getErrorMessage($code)
  1021. {
  1022. $message_list =& $GLOBALS['_Ethna_error_message_list'];
  1023. for ($i = count($message_list)-1; $i >= 0; $i--) {
  1024. if (array_key_exists($code, $message_list[$i])) {
  1025. return $message_list[$i][$code];
  1026. }
  1027. }
  1028. return null;
  1029. }
  1030. /**
  1031. * ?????????????
  1032. *
  1033. * @access private
  1034. * @param mixed $default_action_name ?????????
  1035. * @return string ??????????
  1036. */
  1037. function _getActionName($default_action_name, $fallback_action_name)
  1038. {
  1039. // ??????????????????????
  1040. $form_action_name = $this->_getActionName_Form();
  1041. $form_action_name = preg_replace('/[^a-z0-9\-_]+/i', '', $form_action_name);
  1042. $this->logger->log(LOG_DEBUG, 'form_action_name[%s]', $form_action_name);
  1043. // Ethna??????????????????????
  1044. if ($form_action_name == "__ethna_info__" ||
  1045. $form_action_name == "__ethna_unittest__") {
  1046. $form_action_name = "";
  1047. }
  1048. // ????????????????????????????????????????
  1049. if ($form_action_name == "" && count($default_action_name) > 0) {
  1050. $tmp = is_array($default_action_name) ? $default_action_name[0] : $default_action_name;
  1051. if ($tmp{strlen($tmp)-1} == '*') {
  1052. $tmp = substr($tmp, 0, -1);
  1053. }
  1054. $this->logger->log(LOG_DEBUG, '-> default_action_name[%s]', $tmp);
  1055. $action_name = $tmp;
  1056. } else {
  1057. $action_name = $form_action_name;
  1058. }
  1059. // ??????????????????????????????????????
  1060. if (is_array($default_action_name)) {
  1061. if ($this->_isAcceptableActionName($action_name, $default_action_name) == false) {
  1062. // ??????????????????$fallback_action_name(or ?????)
  1063. $tmp = $fallback_action_name != "" ? $fallback_action_name : $default_action_name[0];
  1064. if ($tmp{strlen($tmp)-1} == '*') {
  1065. $tmp = substr($tmp, 0, -1);
  1066. }
  1067. $this->logger->log(LOG_DEBUG, '-> fallback_action_name[%s]', $tmp);
  1068. $action_name = $tmp;
  1069. }
  1070. }
  1071. $this->logger->log(LOG_DEBUG, '<<< action_name[%s] >>>', $action_name);
  1072. return $action_name;
  1073. }
  1074. /**
  1075. * ?????????????????????
  1076. *
  1077. * ???????????????????????????????????
  1078. * ???????"action_"??????????"action_"?????????
  1079. * ("action_sample"??"sample")???????????????
  1080. *
  1081. * @access protected
  1082. * @return string ??????????????????
  1083. */
  1084. function _getActionName_Form()
  1085. {
  1086. if (isset($_SERVER['REQUEST_METHOD']) == false) {
  1087. return null;
  1088. }
  1089. $url_handler =& $this->getUrlHandler();
  1090. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  1091. $tmp_vars = $_GET;
  1092. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  1093. $tmp_vars = $_POST;
  1094. }
  1095. if (empty($_SERVER['URL_HANDLER']) == false) {
  1096. $tmp_vars['__url_handler__'] = $_SERVER['URL_HANDLER'];
  1097. $tmp_vars['__url_info__'] = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null;
  1098. $tmp_vars = $url_handler->requestToAction($tmp_vars);
  1099. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  1100. $_GET = array_merge($_GET, $tmp_vars);
  1101. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  1102. $_POST = array_merge($_POST, $tmp_vars);
  1103. }
  1104. $_REQUEST = array_merge($_REQUEST, $tmp_vars);
  1105. }
  1106. if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
  1107. $http_vars =& $_POST;
  1108. } else {
  1109. $http_vars =& $_GET;
  1110. }
  1111. // ??????????????????????????
  1112. $action_name = $sub_action_name = null;
  1113. foreach ($http_vars as $name => $value) {
  1114. if ($value == "" || strncmp($name, 'action_', 7) != 0) {
  1115. continue;
  1116. }
  1117. $tmp = substr($name, 7);
  1118. // type="image"??
  1119. if (preg_match('/_x$/', $name) || preg_match('/_y$/', $name)) {
  1120. $tmp = substr($tmp, 0, strlen($tmp)-2);
  1121. }
  1122. // value="dummy"????????????????
  1123. if ($value == "dummy") {
  1124. $sub_action_name = $tmp;
  1125. } else {
  1126. $action_name = $tmp;
  1127. }
  1128. }
  1129. if ($action_name == null) {
  1130. $action_name = $sub_action_name;
  1131. }
  1132. return $action_name;
  1133. }
  1134. /**
  1135. * ??????????????/HTML?????
  1136. *
  1137. * @access public
  1138. * @param string $action action to request
  1139. * @param string $type hidden, url...
  1140. * @todo consider gateway
  1141. */
  1142. function getActionRequest($action, $type = "hidden")
  1143. {
  1144. $s = null;
  1145. if ($type == "hidden") {
  1146. $s = sprintf('<input type="hidden" name="action_%s" value="true" />', htmlspecialchars($action, ENT_QUOTES));
  1147. } else if ($type == "url") {
  1148. $s = sprintf('action_%s=true', urlencode($action));
  1149. }
  1150. return $s;
  1151. }
  1152. /**
  1153. * ????????????????????????????
  1154. *
  1155. * @access private
  1156. * @param string $action_name ??????
  1157. * @return array ???????
  1158. */
  1159. function &_getAction($action_name, $gateway = null)
  1160. {
  1161. $action = array();
  1162. $gateway = is_null($gateway) ? $this->getGateway() : $gateway;
  1163. switch ($gateway) {
  1164. case GATEWAY_WWW:
  1165. $action =& $this->action;
  1166. break;
  1167. case GATEWAY_CLI:
  1168. $action =& $this->action_cli;
  1169. break;
  1170. case GATEWAY_XMLRPC:
  1171. $action =& $this->action_xmlrpc;
  1172. break;
  1173. }
  1174. $action_obj = array();
  1175. if (isset($action[$action_name])) {
  1176. $action_obj = $action[$action_name];
  1177. if (isset($action_obj['inspect']) && $action_obj['inspect']) {
  1178. return $action_obj;
  1179. }
  1180. } else {
  1181. $this->logger->log(LOG_DEBUG, "action [%s] is not defined -> try default", $action_name);
  1182. }
  1183. // ?????????????????
  1184. $this->_includeActionScript($action_obj, $action_name);
  1185. // ??????
  1186. if (isset($action_obj['class_name']) == false) {
  1187. $action_obj['class_name'] = $this->getDefaultActionClass($action_name);
  1188. }
  1189. if (isset($action_obj['form_name']) == false) {
  1190. $action_obj['form_name'] = $this->getDefaultFormClass($action_name);
  1191. } else if (class_exists($action_obj['form_name']) == false) {
  1192. // ????????????????????????????
  1193. $this->logger->log(LOG_WARNING, 'stated form class is not defined [%s]', $action_obj['form_name']);
  1194. }
  1195. // ???????
  1196. if (class_exists($action_obj['class_name']) == false) {
  1197. $this->logger->log(LOG_NOTICE, 'action class is not defined [%s]', $action_obj['class_name']);
  1198. $_ret_object = null;
  1199. return $_ret_object;
  1200. }
  1201. if (class_exists($action_obj['form_name']) == false) {
  1202. // ???????????????
  1203. $class_name = $this->class_factory->getObjectName('form');
  1204. $this->logger->log(LOG_DEBUG, 'form class is not defined [%s] -> falling back to default [%s]', $action_obj['form_name'], $class_name);
  1205. $action_obj['form_name'] = $class_name;
  1206. }
  1207. $action_obj['inspect'] = true;
  1208. $action[$action_name] = $action_obj;
  1209. return $action[$action_name];
  1210. }
  1211. /**
  1212. * ??????????????????????????????????
  1213. *
  1214. * @access protected
  1215. * @param string $action_name ??????
  1216. * @param string $retval ??????????????
  1217. * @return string ???
  1218. */
  1219. function _sortForward($action_name, $retval)
  1220. {
  1221. return $retval;
  1222. }
  1223. /**
  1224. * ?????????????
  1225. *
  1226. * @access private
  1227. */
  1228. function _createFilterChain()
  1229. {
  1230. $this->filter_chain = array();
  1231. foreach ($this->filter as $filter) {
  1232. $filter_plugin =& $this->plugin->getPlugin('Filter', $filter);
  1233. if (Ethna::isError($filter_plugin)) {
  1234. continue;
  1235. }
  1236. $this->filter_chain[] =& $filter_plugin;
  1237. }
  1238. }
  1239. /**
  1240. * ?????????????????????????
  1241. *
  1242. * @access private
  1243. * @param string $action_name ??????????????
  1244. * @param array $default_action_name ?????????????
  1245. * @return bool true:?? false:???
  1246. */
  1247. function _isAcceptableActionName($action_name, $default_action_name)
  1248. {
  1249. foreach (to_array($default_action_name) as $name) {
  1250. if ($action_name == $name) {
  1251. return true;
  1252. } else if ($name{strlen($name)-1} == '*') {
  1253. if (strncmp($action_name, substr($name, 0, -1), strlen($name)-1) == 0) {
  1254. return true;
  1255. }
  1256. }
  1257. }
  1258. return false;
  1259. }
  1260. /**
  1261. * ??????????????????????(??????????????)
  1262. *
  1263. * @access public
  1264. * @param string $action_name ??????
  1265. * @return string ??????????????
  1266. */
  1267. function getActionFormName($action_name)
  1268. {
  1269. $action_obj =& $this->_getAction($action_name);
  1270. if (is_null($action_obj)) {
  1271. return null;
  1272. }
  1273. return $action_obj['form_name'];
  1274. }
  1275. /**
  1276. * ???????????????????????????????????????
  1277. *
  1278. * ???????[??????ID]_Form_[??????]??????????????????
  1279. *
  1280. * @access public
  1281. * @param string $action_name ??????
  1282. * @return string ??????????
  1283. */
  1284. function getDefaultFormClass($action_name, $gateway = null)
  1285. {
  1286. $gateway_prefix = $this->_getGatewayPrefix($gateway);
  1287. $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
  1288. $r = sprintf("%s_%sForm_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
  1289. $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
  1290. return $r;
  1291. }
  1292. /**
  1293. * getDefaultFormClass()??????????????????????
  1294. *
  1295. * getDefaultFormClass()????????????????????????????
  1296. * ???????(??????)
  1297. *
  1298. * @access public
  1299. * @param string $class_name ????????
  1300. * @return string ??????
  1301. */
  1302. function actionFormToName($class_name)
  1303. {
  1304. $prefix = sprintf("%s_Form_", $this->getAppId());
  1305. if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
  1306. // ???????
  1307. return null;
  1308. }
  1309. $target = $match[1];
  1310. $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
  1311. return $action_name;
  1312. }
  1313. /**
  1314. * ?????????????????????????????????????
  1315. *
  1316. * ???????_getDefaultActionPath()????????(1?????
  1317. * ??????????????????????)?????????
  1318. * ?????????
  1319. *
  1320. * @access public
  1321. * @param string $action_name ??????
  1322. * @return string form class???????????????
  1323. */
  1324. function getDefaultFormPath($action_name)
  1325. {
  1326. return $this->getDefaultActionPath($action_name);
  1327. }
  1328. /**
  1329. * ??????????????????(??????????????)
  1330. *
  1331. * @access public
  1332. * @param string $action_name ????????
  1333. * @return string ??????????
  1334. */
  1335. function getActionClassName($action_name)
  1336. {
  1337. $action_obj =& $this->_getAction($action_name);
  1338. if ($action_obj == null) {
  1339. return null;
  1340. }
  1341. return $action_obj['class_name'];
  1342. }
  1343. /**
  1344. * ????????????????????????????????????????
  1345. *
  1346. * ???????[??????ID]_Action_[??????]??????????????????
  1347. *
  1348. * @access public
  1349. * @param string $action_name ??????
  1350. * @return string ?????????
  1351. */
  1352. function getDefaultActionClass($action_name, $gateway = null)
  1353. {
  1354. $gateway_prefix = $this->_getGatewayPrefix($gateway);
  1355. $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
  1356. $r = sprintf("%s_%sAction_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
  1357. $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
  1358. return $r;
  1359. }
  1360. /**
  1361. * getDefaultActionClass()??????????????????????
  1362. *
  1363. * getDefaultActionClass()????????????????????????????
  1364. * ???????(??????)
  1365. *
  1366. * @access public
  1367. * @param string $class_name ?????????
  1368. * @return string ??????
  1369. */
  1370. function actionClassToName($class_name)
  1371. {
  1372. $prefix = sprintf("%s_Action_", $this->getAppId());
  1373. if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
  1374. // ???????
  1375. return null;
  1376. }
  1377. $target = $match[1];
  1378. $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
  1379. return $action_name;
  1380. }
  1381. /**
  1382. * ??????????????????????????????????????
  1383. *
  1384. * ???????"foo_bar" -> "/Foo/Bar.php"???????????????????
  1385. *
  1386. * @access public
  1387. * @param string $action_name ??????
  1388. * @return string ???????????????????????
  1389. */
  1390. function getDefaultActionPath($action_name)
  1391. {
  1392. $r = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($action_name)) . '.' . $this->getExt('php');
  1393. $this->logger->log(LOG_DEBUG, "default action path [%s]", $r);
  1394. return $r;
  1395. }
  1396. /**
  1397. * ???????????????????????(??????????????)
  1398. *
  1399. * @access public
  1400. * @param string $forward_name ??????
  1401. * @return string view class?????
  1402. */
  1403. function getViewClassName($forward_name)
  1404. {
  1405. if ($forward_name == null) {
  1406. return null;
  1407. }
  1408. if (isset($this->forward[$forward_name])) {
  1409. $forward_obj = $this->forward[$forward_name];
  1410. } else {
  1411. $forward_obj = array();
  1412. }
  1413. if (isset($forward_obj['view_name'])) {
  1414. $class_name = $forward_obj['view_name'];
  1415. if (class_exists($class_name)) {
  1416. return $class_name;
  1417. }
  1418. } else {
  1419. $class_name = null;
  1420. }
  1421. // view???????
  1422. $this->_includeViewScript($forward_obj, $forward_name);
  1423. if (is_null($class_name) == false && class_exists($class_name)) {
  1424. return $class_name;
  1425. } else if (is_null($class_name) == false) {
  1426. $this->logger->log(LOG_WARNING, 'stated view class is not defined [%s] -> try default', $class_name);
  1427. }
  1428. $class_name = $this->getDefaultViewClass($forward_name);
  1429. if (class_exists($class_name)) {
  1430. return $class_name;
  1431. } else {
  1432. $class_name = $this->class_factory->getObjectName('view');
  1433. $this->logger->log(LOG_DEBUG, 'view class is not defined for [%s] -> use default [%s]', $forward_name, $class_name);
  1434. return $class_name;
  1435. }
  1436. }
  1437. /**
  1438. * ????????????????????????????????????
  1439. *
  1440. * ???????[??????ID]_View_[???]??????????????????
  1441. *
  1442. * @access public
  1443. * @param string $forward_name forward?
  1444. * @return string view class????
  1445. */
  1446. function getDefaultViewClass($forward_name, $gateway = null)
  1447. {
  1448. $gateway_prefix = $this->_getGatewayPrefix($gateway);
  1449. $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($forward_name));
  1450. $r = sprintf("%s_%sView_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
  1451. $this->logger->log(LOG_DEBUG, "default view class [%s]", $r);
  1452. return $r;
  1453. }
  1454. /**
  1455. * ??????????????????????????????????
  1456. *
  1457. * ???????"foo_bar" -> "/Foo/Bar.php"???????????????????
  1458. *
  1459. * @access public
  1460. * @param string $forward_name forward?
  1461. * @return string view class???????????????
  1462. */
  1463. function getDefaultViewPath($forward_name)
  1464. {
  1465. $r = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($forward_name)) . '.' . $this->getExt('php');
  1466. $this->logger->log(LOG_DEBUG, "default view path [%s]", $r);
  1467. return $r;
  1468. }
  1469. /**
  1470. * ?????????????????????????????????????
  1471. *
  1472. * ???????"foo_bar"???forward??"foo/bar" + ????????????
  1473. * ???????????????
  1474. *
  1475. * @access public
  1476. * @param string $forward_name forward?
  1477. * @return string forward???
  1478. */
  1479. function getDefaultForwardPath($forward_name)
  1480. {
  1481. return str_replace('_', '/', $forward_name) . '.' . $this->ext['tpl'];
  1482. }
  1483. /**
  1484. * ???????????????????
  1485. *
  1486. * getDefaultForwardPath()????????????????????????????
  1487. * ???????(??????)
  1488. *
  1489. * @access public
  1490. * @param string $forward_path ?????????
  1491. * @return string ???
  1492. */
  1493. function forwardPathToName($forward_path)
  1494. {
  1495. $forward_path = preg_replace('/^\/+/', '', $forward_path);
  1496. $forward_path = preg_replace(sprintf('/\.%s$/', $this->getExt('tpl')), '', $forward_path);
  1497. return str_replace('/', '_', $forward_path);
  1498. }
  1499. /**
  1500. * ????????????????????????
  1501. *
  1502. * @access private
  1503. * @param string $forward_name forward?
  1504. * @return string ??????????????
  1505. */
  1506. function _getForwardPath($forward_name)
  1507. {
  1508. $forward_obj = null;
  1509. if (isset($this->forward[$forward_name]) == false) {
  1510. // try default
  1511. $this->forward[$forward_name] = array();
  1512. }
  1513. $forward_obj =& $this->forward[$forward_name];
  1514. if (isset($forward_obj['forward_path']) == false) {
  1515. // ?????
  1516. $forward_obj['forward_path'] = $this->getDefaultForwardPath($forward_name);
  1517. }
  1518. return $forward_obj['forward_path'];
  1519. }
  1520. /**
  1521. * ?????????(getTemplateEngine()?????????getRenderer()????????)
  1522. *
  1523. * @access public
  1524. * @return object Ethna_Renderer ??????????
  1525. */
  1526. function &getRenderer()
  1527. {
  1528. $_ret_object =& $this->getTemplateEngine();
  1529. return $_ret_object;
  1530. }
  1531. /**
  1532. * ??????????????
  1533. *
  1534. * @access public
  1535. * @return object Ethna_Renderer ??????????
  1536. * @obsolete
  1537. */
  1538. function &getTemplateEngine()
  1539. {
  1540. if (is_object($this->renderer)) {
  1541. return $this->renderer;
  1542. }
  1543. $this->renderer =& $this->class_factory->getObject('renderer');
  1544. //???????????????????
  1545. $this->_setDefaultTemplateEngine($this->renderer);
  1546. // }}}
  1547. return $this->renderer;
  1548. }
  1549. /**
  1550. * ???????????????????????
  1551. *
  1552. * @access protected
  1553. * @param object Ethna_Renderer ??????????
  1554. * @obsolete
  1555. */
  1556. function _setDefaultTemplateEngine(&$renderer)
  1557. {
  1558. }
  1559. /**
  1560. * ??????????????
  1561. * ??????????????????????????
  1562. * ?????????????????
  1563. *
  1564. * @access protected
  1565. * @param string $locale ?????(ja_JP, en_US?)
  1566. * (ll_cc ????ll = ????? cc = ????)
  1567. * @param string $system_encoding ?????????????
  1568. * @param string $client_encoding ??????????????(??????????????????????)
  1569. * @see http://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html
  1570. * @see Ethna_Controller#_getDefaultLanguage
  1571. */
  1572. function _setLanguage($locale, $system_encoding = null, $client_encoding = null)
  1573. {
  1574. $this->locale = $locale;
  1575. $this->system_encodin

Large files files are truncated, but you can click here to view the full file