/extras/installer-ftp/lib/Curaga/class/Ethna_Controller.php
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
- <?php
- // vim: foldmethod=marker
- /**
- * Ethna_Controller.php
- *
- * @author Masaki Fujimoto <fujimoto@php.net>
- * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
- * @package Ethna
- * @version $Id: Ethna_Controller.php 866 2009-06-17 17:01:20Z mumumu-org $
- */
- // {{{ Ethna_Controller
- /**
- * ?????????
- *
- * @todo gateway?switch???????????
- *
- * @author Masaki Fujimoto <fujimoto@php.net>
- * @access public
- * @package Ethna
- */
- class Ethna_Controller
- {
- /**#@+
- * @access private
- */
- /** @var string ????????ID */
- var $appid = 'ETHNA';
- /** @var string ????????????????? */
- var $base = '';
- /** @var string ???????????URL */
- var $url = '';
- /** @var string ????????DSN(Data Source Name) */
- var $dsn;
- /** @var array ?????????????? */
- var $directory = array();
- /** @var array ??????????????(?????) */
- var $directory_default = array(
- 'action' => 'app/action',
- 'action_cli' => 'app/action_cli',
- 'action_xmlrpc' => 'app/action_xmlrpc',
- 'app' => 'app',
- 'plugin' => 'app/plugin',
- 'bin' => 'bin',
- 'etc' => 'etc',
- 'filter' => 'app/filter',
- 'locale' => 'locale',
- 'log' => 'log',
- 'plugins' => array(),
- 'template' => 'template',
- 'template_c' => 'tmp',
- 'tmp' => 'tmp',
- 'view' => 'app/view',
- 'www' => 'www',
- 'test' => 'app/test',
- );
- /** @var array DB?????? */
- var $db = array(
- '' => DB_TYPE_RW,
- );
- /** @var array ????? */
- var $ext = array(
- 'php' => 'php',
- 'tpl' => 'tpl',
- );
- /** @var array ????? */
- var $class = array();
- /** @var array ?????(?????) */
- var $class_default = array(
- 'class' => 'Ethna_ClassFactory',
- 'backend' => 'Ethna_Backend',
- 'config' => 'Ethna_Config',
- 'db' => 'Ethna_DB',
- 'error' => 'Ethna_ActionError',
- 'form' => 'Ethna_ActionForm',
- 'i18n' => 'Ethna_I18N',
- 'logger' => 'Ethna_Logger',
- 'plugin' => 'Ethna_Plugin',
- 'renderer' => 'Ethna_Renderer_Smarty',
- 'session' => 'Ethna_Session',
- 'sql' => 'Ethna_AppSQL',
- 'view' => 'Ethna_ViewClass',
- 'url_handler' => 'Ethna_UrlHandler',
- );
- /** @var array ?????? */
- var $filter = array(
- );
- /** @var string ???????? */
- var $locale;
- /** @var string ????????????? */
- var $system_encoding;
- /** @var string ??????????????? */
- /** ?????????????????? */
- var $client_encoding;
- /** @var string ???????????? */
- var $action_name;
- /** @var string ??????XMLRPC????? */
- var $xmlrpc_method_name;
- /** @var array forward?? */
- var $forward = array();
- /** @var array ??????forward?? */
- var $forward_default = array(
- '403' => array( 'view_name' => 'Ethna_View_403',),
- '404' => array( 'view_name' => 'Ethna_View_404',),
- '500' => array( 'view_name' => 'Ethna_View_500',),
- 'json' => array( 'view_name' => 'Ethna_View_Json',),
- 'redirect' => array( 'view_name' => 'Ethna_View_Redirect',),
- );
- /** @var array action?? */
- var $action = array();
- /** @var array action(CLI)?? */
- var $action_cli = array();
- /** @var array action(XMLRPC)?? */
- var $action_xmlrpc = array();
- /** @var array ??????????????? */
- var $manager = array();
- /** @var object ????? */
- var $renderer = null;
- /** @var array ?????????(Ethna_Filter?????????) */
- var $filter_chain = array();
- /** @var object Ethna_ClassFactory ?????????????? */
- var $class_factory = null;
- /** @var object Ethna_ActionForm ?????????? */
- var $action_form = null;
- /** @var object Ethna_View ????????? */
- var $view = null;
- /** @var object Ethna_Config ???????? */
- var $config = null;
- /** @var object Ethna_Logger ???????? */
- var $logger = null;
- /** @var object Ethna_Plugin ??????????? */
- var $plugin = null;
- /** @var string ????????????(www/cli/rest/xmlrpc/soap...) */
- var $gateway = GATEWAY_WWW;
- /**#@-*/
- /**
- * Ethna_Controller???????????
- *
- * @access public
- */
- function Ethna_Controller($gateway = GATEWAY_WWW)
- {
- $GLOBALS['_Ethna_controller'] =& $this;
- if ($this->base === "") {
- // Ethna???????BASE??????????????
- if (defined('BASE')) {
- $this->base = BASE;
- }
- }
- $this->gateway = $gateway;
- // ?????????????
- foreach ($this->class_default as $key => $val) {
- if (isset($this->class[$key]) == false) {
- $this->class[$key] = $val;
- }
- }
- // ????????????????
- foreach ($this->directory_default as $key => $val) {
- if (isset($this->directory[$key]) == false) {
- $this->directory[$key] = $val;
- }
- }
- // ?????????????????
- $class_factory = $this->class['class'];
- $this->class_factory =& new $class_factory($this, $this->class);
- // ??????????
- Ethna::setErrorCallback(array(&$this, 'handleError'));
- // ??????????(????->????)
- foreach ($this->directory as $key => $value) {
- if ($key == 'plugins') {
- // Smarty???????????????????
- $tmp = array();
- foreach (to_array($value) as $elt) {
- if (Ethna_Util::isAbsolute($elt) == false) {
- $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt;
- }
- }
- $this->directory[$key] = $tmp;
- } else {
- if (Ethna_Util::isAbsolute($value) == false) {
- $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value;
- }
- }
- }
- // ?????????
- // ?????????????
- $this->forward = $this->forward + $this->forward_default;
- // ????
- // ????????????????????????????
- // ?????????=???????????????)
- //
- // @see Ethna_Controller#_getDefaultLanguage
- list($this->locale, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage();
- if (mb_enabled()) {
- mb_internal_encoding($this->client_encoding);
- mb_regex_encoding($this->client_encoding);
- }
- $this->config =& $this->getConfig();
- $this->dsn = $this->_prepareDSN();
- $this->url = $this->config->get('url');
- // ??????????????
- $this->plugin =& $this->getPlugin();
- //// assert (experimental)
- //if ($this->config->get('debug') === false) {
- // ini_set('assert.active', 0);
- //}
- // ??????
- $this->logger =& $this->getLogger();
- $this->plugin->setLogger($this->logger);
- $this->logger->begin();
- // Ethna???????
- $this->_activateEthnaManager();
- }
- /**
- * ?????????????????????
- *
- * @access protected
- */
- function end()
- {
- // ??????????????????
- $this->logger->end();
- }
- /**
- * (????????)????????????????
- *
- * @access public
- * @return object Ethna_Controller ?????????????
- * @static
- */
- function &getInstance()
- {
- if (isset($GLOBALS['_Ethna_controller'])) {
- return $GLOBALS['_Ethna_controller'];
- } else {
- $_ret_object = null;
- return $_ret_object;
- }
- }
- /**
- * ????????ID???
- *
- * @access public
- * @return string ????????ID
- */
- function getAppId()
- {
- return ucfirst(strtolower($this->appid));
- }
- /**
- * ????????ID???????
- *
- * @access public
- * @param string $id ????????ID
- * @return mixed true:OK Ethna_Error:NG
- * @static
- */
- function &checkAppId($id)
- {
- $true = true;
- if (strcasecmp($id, 'ethna') === 0
- || strcasecmp($id, 'app') === 0) {
- return Ethna::raiseError("Application Id [$id] is reserved\n");
- }
- // ????????ID??????prefix???????
- // ??????????????
- // @see http://www.php.net/manual/en/language.variables.php
- if (preg_match('/^[a-zA-Z][a-zA-Z0-9]*$/', $id) === 0) {
- $msg = (preg_match('/^[0-9]$/', $id[0]))
- ? "Application ID must NOT start with Number.\n"
- : "Only Numeric(0-9) and Alphabetical(A-Z) is allowed for Application Id\n";
- return Ethna::raiseError($msg);
- }
- return $true;
- }
- /**
- * ?????????????
- *
- * @access public
- * @param string $action_name ??????
- * @return mixed true:OK Ethna_Error:NG
- * @static
- */
- function &checkActionName($action_name)
- {
- $true = true;
- if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
- $action_name) === 0) {
- return Ethna::raiseError("invalid action name [$action_name]");
- }
- return $true;
- }
- /**
- * ???????????
- *
- * @access public
- * @param string $view_name ????
- * @return mixed true:OK Ethna_Error:NG
- * @static
- */
- function &checkViewName($view_name)
- {
- $true = true;
- if (preg_match('/^[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',
- $view_name) === 0) {
- return Ethna::raiseError("invalid view name [$view_name]");
- }
- return $true;
- }
- /**
- * DSN???
- *
- * @access public
- * @param string $db_key DB??
- * @return string DSN
- */
- function getDSN($db_key = "")
- {
- if (isset($this->dsn[$db_key]) == false) {
- return null;
- }
- return $this->dsn[$db_key];
- }
- /**
- * DSN??????????
- *
- * @access public
- * @param string $db_key DB??
- * @return bool true:persistent false:non-persistent(????????)
- */
- function getDSN_persistent($db_key = "")
- {
- $key = sprintf("dsn%s_persistent", $db_key == "" ? "" : "_$db_key");
- $dsn_persistent = $this->config->get($key);
- if (is_null($dsn_persistent)) {
- return false;
- }
- return $dsn_persistent;
- }
- /**
- * DB?????
- *
- * @access public
- * @param string $db_key DB??("", "r", "rw", "default", "blog_r"...)
- * @return string $db_key?????DB????(????????null)
- */
- function getDBType($db_key = null)
- {
- if (is_null($db_key)) {
- // ?????
- return $this->db;
- }
- if (isset($this->db[$db_key]) == false) {
- return null;
- }
- return $this->db[$db_key];
- }
- /**
- * ???????????URL???
- *
- * @access public
- * @return string ???????????URL
- */
- function getURL()
- {
- return $this->url;
- }
- /**
- * ????????????????????
- *
- * @access public
- * @return string ?????????????????
- */
- function getBasedir()
- {
- return $this->base;
- }
- /**
- * ?????????/??????????????????????
- * ??????? [appid]/template/ja_JP/ (ja_JP??????)
- * ?????? _getDefaultLanguage ???????
- *
- * @access public
- * @return string ????????????
- * @see Ethna_Controller#_getDefaultLanguage
- */
- function getTemplatedir()
- {
- $template = $this->getDirectory('template');
- // ?????????
- // _getDerfaultLanguage?????????????????????
- // ??????????????????????????
- if (!empty($this->locale)) {
- $template .= '/' . $this->locale;
- }
- return $template;
- }
- /**
- * ?????????????????
- *
- * @access public
- * @return string ???????????
- */
- function getActiondir($gateway = null)
- {
- $key = 'action';
- $gateway = is_null($gateway) ? $this->getGateway() : $gateway;
- switch ($gateway) {
- case GATEWAY_WWW:
- $key = 'action';
- break;
- case GATEWAY_CLI:
- $key = 'action_cli';
- break;
- case GATEWAY_XMLRPC:
- $key = 'action_xmlrpc';
- break;
- }
- return (empty($this->directory[$key]) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory[$key] . "/"));
- }
- /**
- * ???????????????
- *
- * @access public
- * @return string ?????????
- */
- function getViewdir()
- {
- return (empty($this->directory['view']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['view'] . "/"));
- }
- /**
- * (action,view???)?????????????????????
- *
- * @access public
- * @return string ???????????????
- */
- function getTestdir()
- {
- return (empty($this->directory['test']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['test'] . "/"));
- }
- /**
- * ???????????????????
- *
- * @access public
- * @param string $key ?????????("tmp", "template"...)
- * @return string $key???????????????????(????????null)
- */
- function getDirectory($key)
- {
- if (isset($this->directory[$key]) == false) {
- return null;
- }
- return $this->directory[$key];
- }
- /**
- * ????????????????
- *
- * @access public
- * @param string $key ??????("php", "tpl"...)
- * @return string $key????????(????????null)
- */
- function getExt($key)
- {
- if (isset($this->ext[$key]) == false) {
- return null;
- }
- return $this->ext[$key];
- }
- /**
- * ???????????????????(R)
- *
- * @access public
- * @return object Ethna_ClassFactory ??????????????
- */
- function &getClassFactory()
- {
- return $this->class_factory;
- }
- /**
- * ???????????????????
- *
- * @access public
- * @return object Ethna_ActionError ??????????????
- */
- function &getActionError()
- {
- return $this->class_factory->getObject('error');
- }
- /**
- * ????????????????????
- *
- * @access public
- * @return object Ethna_ActionForm ???????????????
- */
- function &getActionForm()
- {
- // ????????????????????
- return $this->action_form;
- }
- /**
- * ??????????????
- *
- * @access public
- * @return object Ethna_View ?????????
- */
- function &getView()
- {
- // ????????????????????
- return $this->view;
- }
- /**
- * backend???????????
- *
- * @access public
- * @return object Ethna_Backend backend??????
- */
- function &getBackend()
- {
- return $this->class_factory->getObject('backend');
- }
- /**
- * ?????????????
- *
- * @access public
- * @return object Ethna_Config ????????
- */
- function &getConfig()
- {
- return $this->class_factory->getObject('config');
- }
- /**
- * i18n???????????(R)
- *
- * @access public
- * @return object Ethna_I18N i18n??????
- */
- function &getI18N()
- {
- return $this->class_factory->getObject('i18n');
- }
- /**
- * ?????????????
- *
- * @access public
- * @return object Ethna_Logger ????????
- */
- function &getLogger()
- {
- return $this->class_factory->getObject('logger');
- }
- /**
- * ????????????????
- *
- * @access public
- * @return object Ethna_Session ???????????
- */
- function &getSession()
- {
- return $this->class_factory->getObject('session');
- }
- /**
- * SQL???????????
- *
- * @access public
- * @return object Ethna_AppSQL SQL??????
- */
- function &getSQL()
- {
- return $this->class_factory->getObject('sql');
- }
- /**
- * ????????????????
- *
- * @access public
- * @return object Ethna_Plugin ???????????
- */
- function &getPlugin()
- {
- return $this->class_factory->getObject('plugin');
- }
- /**
- * URL???????????????
- *
- * @access public
- * @return object Ethna_UrlHandler URL??????????
- */
- function &getUrlHandler()
- {
- return $this->class_factory->getObject('url_handler');
- }
- /**
- * ??????????
- *
- * @access public
- * @return array ???????
- * @obsolete
- */
- function getManagerList()
- {
- return $this->manager;
- }
- /**
- * ?????????????
- *
- * @access public
- * @return string ??????????
- */
- function getCurrentActionName()
- {
- return $this->action_name;
- }
- /**
- * ????XMLRPC????????
- *
- * @access public
- * @return string ????XMLRPC?????
- */
- function getXmlrpcMethodName()
- {
- return $this->xmlrpc_method_name;
- }
- /**
- * ????????????????
- *
- * @access public
- * @return array ?????(e.x ja_JP, en_US ?),
- * ?????????????,
- * ??????????????? ???
- * (???????ll_cc ????ll = ????? cc = ????)
- * @see http://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html
- */
- function getLanguage()
- {
- return array($this->locale, $this->system_encoding, $this->client_encoding);
- }
- /**
- * ???????????(R)
- *
- * @access public
- * @return string ?????(e.x ja_JP, en_US ?),
- * (???????ll_cc ????ll = ????? cc = ????)
- */
- function getLocale()
- {
- return $this->locale;
- }
- /**
- * ???????????(W)
- *
- * @access public
- * @param $locale ?????(e.x ja_JP, en_US ?),
- * (???????ll_cc ????ll = ????? cc = ????)
- */
- function setLocale($locale)
- {
- $this->locale = $locale;
- $i18n =& $this->getI18N();
- $i18n->setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
- }
- /**
- * ?????????????????????(R)
- *
- * @access public
- * @return string $client_encoding ???????????????
- */
- function getClientEncoding()
- {
- return $this->client_encoding;
- }
- /**
- * ?????????????????????(W)
- *
- * @access public
- * @param string $client_encoding ???????????????
- */
- function setClientEncoding($client_encoding)
- {
- $this->client_encoding = $client_encoding;
- $i18n =& $this->getI18N();
- $i18n->setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
- }
- /**
- * ???????????
- *
- * @access public
- */
- function getGateway()
- {
- return $this->gateway;
- }
- /**
- * ??????????????
- *
- * @access public
- */
- function setGateway($gateway)
- {
- $this->gateway = $gateway;
- }
- /**
- * ?????????????????
- *
- * @access public
- * @param string $class_name ???????????????????
- * @param mixed $action_name ?????????(???)
- * @param mixed $fallback_action_name ????????????????????????????(???)
- * @static
- */
- function main($class_name, $action_name = "", $fallback_action_name = "")
- {
- $c =& new $class_name;
- $c->trigger($action_name, $fallback_action_name);
- $c->end();
- }
- /**
- * CLI?????????????????
- *
- * @access public
- * @param string $class_name ???????????????????
- * @param string $action_name ??????????
- * @param bool $enable_filter ??????????????????
- * @static
- */
- function main_CLI($class_name, $action_name, $enable_filter = true)
- {
- $c =& new $class_name(GATEWAY_CLI);
- $c->action_cli[$action_name] = array();
- $c->trigger($action_name, "", $enable_filter);
- $c->end();
- }
- /**
- * XMLRPC?????????????????
- *
- * @access public
- * @static
- */
- function main_XMLRPC($class_name)
- {
- if (extension_loaded('xmlrpc') == false) {
- die("xmlrpc extension is required to enable this gateway");
- }
- $c =& new $class_name(GATEWAY_XMLRPC);
- $c->trigger("", "", false);
- $c->end();
- }
- /**
- * SOAP?????????????????
- *
- * @access public
- * @param string $class_name ???????????????????
- * @param mixed $action_name ?????????(???)
- * @param mixed $fallback_action_name ????????????????????????????(???)
- * @static
- */
- function main_SOAP($class_name, $action_name = "", $fallback_action_name = "")
- {
- $c =& new $class_name(GATEWAY_SOAP);
- $c->trigger($action_name, $fallback_action_name);
- $c->end();
- }
- /**
- * ???????????????
- *
- * @access public
- * @param mixed $default_action_name ?????????
- * @param mixed $fallback_action_name ?????????????????????????????
- * @param bool $enable_filter ??????????????????
- * @return mixed 0:???? Ethna_Error:???
- */
- function trigger($default_action_name = "", $fallback_action_name = "", $enable_filter = true)
- {
- // ????????
- if ($enable_filter) {
- $this->_createFilterChain();
- }
- // ???????
- for ($i = 0; $i < count($this->filter_chain); $i++) {
- $r = $this->filter_chain[$i]->preFilter();
- if (Ethna::isError($r)) {
- return $r;
- }
- }
- // trigger
- switch ($this->getGateway()) {
- case GATEWAY_WWW:
- $this->_trigger_WWW($default_action_name, $fallback_action_name);
- break;
- case GATEWAY_CLI:
- $this->_trigger_CLI($default_action_name);
- break;
- case GATEWAY_XMLRPC:
- $this->_trigger_XMLRPC();
- break;
- case GATEWAY_SOAP:
- $this->_trigger_SOAP();
- break;
- }
- // ???????
- for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
- $r = $this->filter_chain[$i]->postFilter();
- if (Ethna::isError($r)) {
- return $r;
- }
- }
- }
- /**
- * ???????????????(WWW)
- *
- * ??$default_action_name??????????????????????
- * ??????????????(???????????????????
- * ?????????????????????????)
- *
- * @access private
- * @param mixed $default_action_name ?????????
- * @param mixed $fallback_action_name ?????????????????????????????
- * @return mixed 0:???? Ethna_Error:???
- */
- function _trigger_WWW($default_action_name = "", $fallback_action_name = "")
- {
- // ?????????
- $action_name = $this->_getActionName($default_action_name, $fallback_action_name);
- // ???????????
- $this->_ethnaManagerEnabledCheck($action_name);
- // ??????????
- $action_obj =& $this->_getAction($action_name);
- if (is_null($action_obj)) {
- if ($fallback_action_name != "") {
- $this->logger->log(LOG_DEBUG, 'undefined action [%s] -> try fallback action [%s]', $action_name, $fallback_action_name);
- $action_obj =& $this->_getAction($fallback_action_name);
- }
- if (is_null($action_obj)) {
- return Ethna::raiseError("undefined action [%s]", E_APP_UNDEFINED_ACTION, $action_name);
- } else {
- $action_name = $fallback_action_name;
- }
- }
- // ????????????
- for ($i = 0; $i < count($this->filter_chain); $i++) {
- $r = $this->filter_chain[$i]->preActionFilter($action_name);
- if ($r != null) {
- $this->logger->log(LOG_DEBUG, 'action [%s] -> [%s] by %s', $action_name, $r, get_class($this->filter_chain[$i]));
- $action_name = $r;
- }
- }
- $this->action_name = $action_name;
- // ????????
- $backend =& $this->getBackend();
- $session =& $this->getSession();
- $session->restore();
- // ????????????
- $this->_setLanguage($this->locale, $this->system_encoding, $this->client_encoding);
- // ????????????
- // ??????????????
- $form_name = $this->getActionFormName($action_name);
- $this->action_form =& new $form_name($this);
- $this->action_form->setFormDef_PreHelper();
- $this->action_form->setFormVars();
- $backend->setActionForm($this->action_form);
- // ??????????
- $forward_name = $backend->perform($action_name);
- // ????????????
- for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
- $r = $this->filter_chain[$i]->postActionFilter($action_name, $forward_name);
- if ($r != null) {
- $this->logger->log(LOG_DEBUG, 'forward [%s] -> [%s] by %s', $forward_name, $r, get_class($this->filter_chain[$i]));
- $forward_name = $r;
- }
- }
- // ???????????????(?????)
- $forward_name_params = $this->_sortForward($action_name, $forward_name);
- // View????????????
- $preforward_params = array();
- if (is_array($forward_name_params)) {
- $forward_name = array_shift($forward_name_params);
- $preforward_params = $forward_name_params;
- }
- else {
- $forward_name = $forward_name_params;
- }
- if ($forward_name != null) {
- $view_class_name = $this->getViewClassName($forward_name);
- $this->view =& new $view_class_name($backend, $forward_name, $this->_getForwardPath($forward_name));
- call_user_func_array(array($this->view, 'preforward'), $preforward_params);
- $this->view->forward();
- }
- return 0;
- }
- /**
- * ???????????????(CLI)
- *
- * @access private
- * @param mixed $default_action_name ?????????
- * @return mixed 0:???? Ethna_Error:???
- */
- function _trigger_CLI($default_action_name = "")
- {
- return $this->_trigger_WWW($default_action_name);
- }
- /**
- * ???????????????(XMLRPC)
- *
- * @access private
- * @param mixed $action_name ?????????
- * @return mixed 0:???? Ethna_Error:???
- */
- function _trigger_XMLRPC($action_name = "")
- {
- // prepare xmlrpc server
- $xmlrpc_gateway_method_name = "_Ethna_XmlrpcGateway";
- $xmlrpc_server = xmlrpc_server_create();
- $method = null;
- $param = xmlrpc_decode_request(file_get_contents('php://input'), $method);
- $this->xmlrpc_method_name = $method;
- $request = xmlrpc_encode_request(
- $xmlrpc_gateway_method_name,
- $param,
- array(
- 'output_type' => 'xml',
- 'verbosity' => 'pretty',
- 'escaping' => array('markup'),
- 'version' => 'xmlrpc',
- 'encoding' => 'utf-8'
- )
- );
- xmlrpc_server_register_method(
- $xmlrpc_server,
- $xmlrpc_gateway_method_name,
- $xmlrpc_gateway_method_name
- );
- // send request
- $r = xmlrpc_server_call_method(
- $xmlrpc_server,
- $request,
- null,
- array(
- 'output_type' => 'xml',
- 'verbosity' => 'pretty',
- 'escaping' => array('markup'),
- 'version' => 'xmlrpc',
- 'encoding' => 'utf-8'
- )
- );
- header('Content-Length: ' . strlen($r));
- header('Content-Type: text/xml; charset=UTF-8');
- print $r;
- }
- /**
- * _trigger_XMLRPC???????????
- *
- * @access public
- */
- function trigger_XMLRPC($method, $param)
- {
- // ??????????
- $action_obj =& $this->_getAction($method);
- if (is_null($action_obj)) {
- return Ethna::raiseError("undefined xmlrpc method [%s]", E_APP_UNDEFINED_ACTION, $method);
- }
- // ????????
- $backend =& $this->getBackend();
- $form_name = $this->getActionFormName($method);
- $this->action_form =& new $form_name($this);
- $def = $this->action_form->getDef();
- $n = 0;
- foreach ($def as $key => $value) {
- if (isset($param[$n]) == false) {
- $this->action_form->set($key, null);
- } else {
- $this->action_form->set($key, $param[$n]);
- }
- $n++;
- }
- // ??????????
- $backend->setActionForm($this->action_form);
- $session =& $this->getSession();
- $session->restore();
- $r = $backend->perform($method);
- return $r;
- }
- /**
- * SOAP???????????????
- *
- * @access private
- */
- function _trigger_SOAP()
- {
- // SOAP???????
- $gg =& new Ethna_SOAP_GatewayGenerator();
- $script = $gg->generate();
- eval($script);
- // SOAP???????
- $server =& new SoapServer(null, array('uri' => $this->config->get('url')));
- $server->setClass($gg->getClassName());
- $server->handle();
- }
- /**
- * ???????
- *
- * ???????????????????????????????????
- * (???????????????????????????????
- * ??????????????????????????????
- * ????????)
- *
- * @access public
- * @param object Ethna_Error ?????????
- */
- function handleError(&$error)
- {
- // ????
- list ($log_level, $dummy) = $this->logger->errorLevelToLogLevel($error->getLevel());
- $message = $error->getMessage();
- $this->logger->log($log_level, sprintf("%s [ERROR CODE(%d)]", $message, $error->getCode()));
- }
- /**
- * ?????????????
- *
- * @access public
- * @param int $code ??????
- * @return string ????????
- */
- function getErrorMessage($code)
- {
- $message_list =& $GLOBALS['_Ethna_error_message_list'];
- for ($i = count($message_list)-1; $i >= 0; $i--) {
- if (array_key_exists($code, $message_list[$i])) {
- return $message_list[$i][$code];
- }
- }
- return null;
- }
- /**
- * ?????????????
- *
- * @access private
- * @param mixed $default_action_name ?????????
- * @return string ??????????
- */
- function _getActionName($default_action_name, $fallback_action_name)
- {
- // ??????????????????????
- $form_action_name = $this->_getActionName_Form();
- $form_action_name = preg_replace('/[^a-z0-9\-_]+/i', '', $form_action_name);
- $this->logger->log(LOG_DEBUG, 'form_action_name[%s]', $form_action_name);
- // Ethna??????????????????????
- if ($form_action_name == "__ethna_info__" ||
- $form_action_name == "__ethna_unittest__") {
- $form_action_name = "";
- }
- // ????????????????????????????????????????
- if ($form_action_name == "" && count($default_action_name) > 0) {
- $tmp = is_array($default_action_name) ? $default_action_name[0] : $default_action_name;
- if ($tmp{strlen($tmp)-1} == '*') {
- $tmp = substr($tmp, 0, -1);
- }
- $this->logger->log(LOG_DEBUG, '-> default_action_name[%s]', $tmp);
- $action_name = $tmp;
- } else {
- $action_name = $form_action_name;
- }
- // ??????????????????????????????????????
- if (is_array($default_action_name)) {
- if ($this->_isAcceptableActionName($action_name, $default_action_name) == false) {
- // ??????????????????$fallback_action_name(or ?????)
- $tmp = $fallback_action_name != "" ? $fallback_action_name : $default_action_name[0];
- if ($tmp{strlen($tmp)-1} == '*') {
- $tmp = substr($tmp, 0, -1);
- }
- $this->logger->log(LOG_DEBUG, '-> fallback_action_name[%s]', $tmp);
- $action_name = $tmp;
- }
- }
- $this->logger->log(LOG_DEBUG, '<<< action_name[%s] >>>', $action_name);
- return $action_name;
- }
- /**
- * ?????????????????????
- *
- * ???????????????????????????????????
- * ???????"action_"??????????"action_"?????????
- * ("action_sample"??"sample")???????????????
- *
- * @access protected
- * @return string ??????????????????
- */
- function _getActionName_Form()
- {
- if (isset($_SERVER['REQUEST_METHOD']) == false) {
- return null;
- }
- $url_handler =& $this->getUrlHandler();
- if ($_SERVER['REQUEST_METHOD'] == "GET") {
- $tmp_vars = $_GET;
- } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
- $tmp_vars = $_POST;
- }
- if (empty($_SERVER['URL_HANDLER']) == false) {
- $tmp_vars['__url_handler__'] = $_SERVER['URL_HANDLER'];
- $tmp_vars['__url_info__'] = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null;
- $tmp_vars = $url_handler->requestToAction($tmp_vars);
- if ($_SERVER['REQUEST_METHOD'] == "GET") {
- $_GET = array_merge($_GET, $tmp_vars);
- } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
- $_POST = array_merge($_POST, $tmp_vars);
- }
- $_REQUEST = array_merge($_REQUEST, $tmp_vars);
- }
- if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
- $http_vars =& $_POST;
- } else {
- $http_vars =& $_GET;
- }
- // ??????????????????????????
- $action_name = $sub_action_name = null;
- foreach ($http_vars as $name => $value) {
- if ($value == "" || strncmp($name, 'action_', 7) != 0) {
- continue;
- }
- $tmp = substr($name, 7);
- // type="image"??
- if (preg_match('/_x$/', $name) || preg_match('/_y$/', $name)) {
- $tmp = substr($tmp, 0, strlen($tmp)-2);
- }
- // value="dummy"????????????????
- if ($value == "dummy") {
- $sub_action_name = $tmp;
- } else {
- $action_name = $tmp;
- }
- }
- if ($action_name == null) {
- $action_name = $sub_action_name;
- }
- return $action_name;
- }
- /**
- * ??????????????/HTML?????
- *
- * @access public
- * @param string $action action to request
- * @param string $type hidden, url...
- * @todo consider gateway
- */
- function getActionRequest($action, $type = "hidden")
- {
- $s = null;
- if ($type == "hidden") {
- $s = sprintf('<input type="hidden" name="action_%s" value="true" />', htmlspecialchars($action, ENT_QUOTES));
- } else if ($type == "url") {
- $s = sprintf('action_%s=true', urlencode($action));
- }
- return $s;
- }
- /**
- * ????????????????????????????
- *
- * @access private
- * @param string $action_name ??????
- * @return array ???????
- */
- function &_getAction($action_name, $gateway = null)
- {
- $action = array();
- $gateway = is_null($gateway) ? $this->getGateway() : $gateway;
- switch ($gateway) {
- case GATEWAY_WWW:
- $action =& $this->action;
- break;
- case GATEWAY_CLI:
- $action =& $this->action_cli;
- break;
- case GATEWAY_XMLRPC:
- $action =& $this->action_xmlrpc;
- break;
- }
- $action_obj = array();
- if (isset($action[$action_name])) {
- $action_obj = $action[$action_name];
- if (isset($action_obj['inspect']) && $action_obj['inspect']) {
- return $action_obj;
- }
- } else {
- $this->logger->log(LOG_DEBUG, "action [%s] is not defined -> try default", $action_name);
- }
- // ?????????????????
- $this->_includeActionScript($action_obj, $action_name);
- // ??????
- if (isset($action_obj['class_name']) == false) {
- $action_obj['class_name'] = $this->getDefaultActionClass($action_name);
- }
- if (isset($action_obj['form_name']) == false) {
- $action_obj['form_name'] = $this->getDefaultFormClass($action_name);
- } else if (class_exists($action_obj['form_name']) == false) {
- // ????????????????????????????
- $this->logger->log(LOG_WARNING, 'stated form class is not defined [%s]', $action_obj['form_name']);
- }
- // ???????
- if (class_exists($action_obj['class_name']) == false) {
- $this->logger->log(LOG_NOTICE, 'action class is not defined [%s]', $action_obj['class_name']);
- $_ret_object = null;
- return $_ret_object;
- }
- if (class_exists($action_obj['form_name']) == false) {
- // ???????????????
- $class_name = $this->class_factory->getObjectName('form');
- $this->logger->log(LOG_DEBUG, 'form class is not defined [%s] -> falling back to default [%s]', $action_obj['form_name'], $class_name);
- $action_obj['form_name'] = $class_name;
- }
- $action_obj['inspect'] = true;
- $action[$action_name] = $action_obj;
- return $action[$action_name];
- }
- /**
- * ??????????????????????????????????
- *
- * @access protected
- * @param string $action_name ??????
- * @param string $retval ??????????????
- * @return string ???
- */
- function _sortForward($action_name, $retval)
- {
- return $retval;
- }
- /**
- * ?????????????
- *
- * @access private
- */
- function _createFilterChain()
- {
- $this->filter_chain = array();
- foreach ($this->filter as $filter) {
- $filter_plugin =& $this->plugin->getPlugin('Filter', $filter);
- if (Ethna::isError($filter_plugin)) {
- continue;
- }
- $this->filter_chain[] =& $filter_plugin;
- }
- }
- /**
- * ?????????????????????????
- *
- * @access private
- * @param string $action_name ??????????????
- * @param array $default_action_name ?????????????
- * @return bool true:?? false:???
- */
- function _isAcceptableActionName($action_name, $default_action_name)
- {
- foreach (to_array($default_action_name) as $name) {
- if ($action_name == $name) {
- return true;
- } else if ($name{strlen($name)-1} == '*') {
- if (strncmp($action_name, substr($name, 0, -1), strlen($name)-1) == 0) {
- return true;
- }
- }
- }
- return false;
- }
- /**
- * ??????????????????????(??????????????)
- *
- * @access public
- * @param string $action_name ??????
- * @return string ??????????????
- */
- function getActionFormName($action_name)
- {
- $action_obj =& $this->_getAction($action_name);
- if (is_null($action_obj)) {
- return null;
- }
- return $action_obj['form_name'];
- }
- /**
- * ???????????????????????????????????????
- *
- * ???????[??????ID]_Form_[??????]??????????????????
- *
- * @access public
- * @param string $action_name ??????
- * @return string ??????????
- */
- function getDefaultFormClass($action_name, $gateway = null)
- {
- $gateway_prefix = $this->_getGatewayPrefix($gateway);
- $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
- $r = sprintf("%s_%sForm_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
- $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
- return $r;
- }
- /**
- * getDefaultFormClass()??????????????????????
- *
- * getDefaultFormClass()????????????????????????????
- * ???????(??????)
- *
- * @access public
- * @param string $class_name ????????
- * @return string ??????
- */
- function actionFormToName($class_name)
- {
- $prefix = sprintf("%s_Form_", $this->getAppId());
- if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
- // ???????
- return null;
- }
- $target = $match[1];
- $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
- return $action_name;
- }
- /**
- * ?????????????????????????????????????
- *
- * ???????_getDefaultActionPath()????????(1?????
- * ??????????????????????)?????????
- * ?????????
- *
- * @access public
- * @param string $action_name ??????
- * @return string form class???????????????
- */
- function getDefaultFormPath($action_name)
- {
- return $this->getDefaultActionPath($action_name);
- }
- /**
- * ??????????????????(??????????????)
- *
- * @access public
- * @param string $action_name ????????
- * @return string ??????????
- */
- function getActionClassName($action_name)
- {
- $action_obj =& $this->_getAction($action_name);
- if ($action_obj == null) {
- return null;
- }
- return $action_obj['class_name'];
- }
- /**
- * ????????????????????????????????????????
- *
- * ???????[??????ID]_Action_[??????]??????????????????
- *
- * @access public
- * @param string $action_name ??????
- * @return string ?????????
- */
- function getDefaultActionClass($action_name, $gateway = null)
- {
- $gateway_prefix = $this->_getGatewayPrefix($gateway);
- $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
- $r = sprintf("%s_%sAction_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
- $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
- return $r;
- }
- /**
- * getDefaultActionClass()??????????????????????
- *
- * getDefaultActionClass()????????????????????????????
- * ???????(??????)
- *
- * @access public
- * @param string $class_name ?????????
- * @return string ??????
- */
- function actionClassToName($class_name)
- {
- $prefix = sprintf("%s_Action_", $this->getAppId());
- if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
- // ???????
- return null;
- }
- $target = $match[1];
- $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
- return $action_name;
- }
- /**
- * ??????????????????????????????????????
- *
- * ???????"foo_bar" -> "/Foo/Bar.php"???????????????????
- *
- * @access public
- * @param string $action_name ??????
- * @return string ???????????????????????
- */
- function getDefaultActionPath($action_name)
- {
- $r = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($action_name)) . '.' . $this->getExt('php');
- $this->logger->log(LOG_DEBUG, "default action path [%s]", $r);
- return $r;
- }
- /**
- * ???????????????????????(??????????????)
- *
- * @access public
- * @param string $forward_name ??????
- * @return string view class?????
- */
- function getViewClassName($forward_name)
- {
- if ($forward_name == null) {
- return null;
- }
- if (isset($this->forward[$forward_name])) {
- $forward_obj = $this->forward[$forward_name];
- } else {
- $forward_obj = array();
- }
- if (isset($forward_obj['view_name'])) {
- $class_name = $forward_obj['view_name'];
- if (class_exists($class_name)) {
- return $class_name;
- }
- } else {
- $class_name = null;
- }
- // view???????
- $this->_includeViewScript($forward_obj, $forward_name);
- if (is_null($class_name) == false && class_exists($class_name)) {
- return $class_name;
- } else if (is_null($class_name) == false) {
- $this->logger->log(LOG_WARNING, 'stated view class is not defined [%s] -> try default', $class_name);
- }
- $class_name = $this->getDefaultViewClass($forward_name);
- if (class_exists($class_name)) {
- return $class_name;
- } else {
- $class_name = $this->class_factory->getObjectName('view');
- $this->logger->log(LOG_DEBUG, 'view class is not defined for [%s] -> use default [%s]', $forward_name, $class_name);
- return $class_name;
- }
- }
- /**
- * ????????????????????????????????????
- *
- * ???????[??????ID]_View_[???]??????????????????
- *
- * @access public
- * @param string $forward_name forward?
- * @return string view class????
- */
- function getDefaultViewClass($forward_name, $gateway = null)
- {
- $gateway_prefix = $this->_getGatewayPrefix($gateway);
- $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($forward_name));
- $r = sprintf("%s_%sView_%s", $this->getAppId(), $gateway_prefix ? $gateway_prefix . "_" : "", $postfix);
- $this->logger->log(LOG_DEBUG, "default view class [%s]", $r);
- return $r;
- }
- /**
- * ??????????????????????????????????
- *
- * ???????"foo_bar" -> "/Foo/Bar.php"???????????????????
- *
- * @access public
- * @param string $forward_name forward?
- * @return string view class???????????????
- */
- function getDefaultViewPath($forward_name)
- {
- $r = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($forward_name)) . '.' . $this->getExt('php');
- $this->logger->log(LOG_DEBUG, "default view path [%s]", $r);
- return $r;
- }
- /**
- * ?????????????????????????????????????
- *
- * ???????"foo_bar"???forward??"foo/bar" + ????????????
- * ???????????????
- *
- * @access public
- * @param string $forward_name forward?
- * @return string forward???
- */
- function getDefaultForwardPath($forward_name)
- {
- return str_replace('_', '/', $forward_name) . '.' . $this->ext['tpl'];
- }
- /**
- * ???????????????????
- *
- * getDefaultForwardPath()????????????????????????????
- * ???????(??????)
- *
- * @access public
- * @param string $forward_path ?????????
- * @return string ???
- */
- function forwardPathToName($forward_path)
- {
- $forward_path = preg_replace('/^\/+/', '', $forward_path);
- $forward_path = preg_replace(sprintf('/\.%s$/', $this->getExt('tpl')), '', $forward_path);
- return str_replace('/', '_', $forward_path);
- }
- /**
- * ????????????????????????
- *
- * @access private
- * @param string $forward_name forward?
- * @return string ??????????????
- */
- function _getForwardPath($forward_name)
- {
- $forward_obj = null;
- if (isset($this->forward[$forward_name]) == false) {
- // try default
- $this->forward[$forward_name] = array();
- }
- $forward_obj =& $this->forward[$forward_name];
- if (isset($forward_obj['forward_path']) == false) {
- // ?????
- $forward_obj['forward_path'] = $this->getDefaultForwardPath($forward_name);
- }
- return $forward_obj['forward_path'];
- }
- /**
- * ?????????(getTemplateEngine()?????????getRenderer()????????)
- *
- * @access public
- * @return object Ethna_Renderer ??????????
- */
- function &getRenderer()
- {
- $_ret_object =& $this->getTemplateEngine();
- return $_ret_object;
- }
- /**
- * ??????????????
- *
- * @access public
- * @return object Ethna_Renderer ??????????
- * @obsolete
- */
- function &getTemplateEngine()
- {
- if (is_object($this->renderer)) {
- return $this->renderer;
- }
- $this->renderer =& $this->class_factory->getObject('renderer');
- //???????????????????
- $this->_setDefaultTemplateEngine($this->renderer);
- // }}}
- return $this->renderer;
- }
- /**
- * ???????????????????????
- *
- * @access protected
- * @param object Ethna_Renderer ??????????
- * @obsolete
- */
- function _setDefaultTemplateEngine(&$renderer)
- {
- }
- /**
- * ??????????????
- * ??????????????????????????
- * ?????????????????
- *
- * @access protected
- * @param string $locale ?????(ja_JP, en_US?)
- * (ll_cc ????ll = ????? cc = ????)
- * @param string $system_encoding ?????????????
- * @param string $client_encoding ??????????????(??????????????????????)
- * @see http://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html
- * @see Ethna_Controller#_getDefaultLanguage
- */
- function _setLanguage($locale, $system_encoding = null, $client_encoding = null)
- {
- $this->locale = $locale;
- $this->system_encodin…
Large files files are truncated, but you can click here to view the full file