OSDN Git Service

- Ethna_Controller::getCLI()(CLIで実行中かどうかを返すメソッド)を追加
[ethna/ethna.git] / class / Ethna_Controller.php
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$
10  */
11
12 // {{{ Ethna_Controller
13 /**
14  *      ¥³¥ó¥È¥í¡¼¥é¥¯¥é¥¹
15  *
16  *      @author         Masaki Fujimoto <fujimoto@php.net>
17  *      @access         public
18  *      @package        Ethna
19  */
20 class Ethna_Controller
21 {
22         /**#@+
23          *      @access private
24          */
25
26         /**     @var    string          ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID */
27         var $appid = 'ETHNA';
28
29         /**     @var    string          ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê */
30         var $base = '';
31
32         /**     @var    string          ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL */
33         var     $url = '';
34
35         /**     @var    string          ¥¢¥×¥ê¥±¡¼¥·¥ç¥óDSN(Data Source Name) */
36         var $dsn;
37
38         /**     @var    array           ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê */
39         var $directory = array(
40                 'action'                => 'app/action',
41                 'etc'                   => 'etc',
42                 'filter'                => 'app/filter',
43                 'locale'                => 'locale',
44                 'log'                   => 'log',
45                 'plugins'               => array(),
46                 'template'              => 'template',
47                 'template_c'    => 'tmp',
48                 'tmp'                   => 'tmp',
49                 'view'                  => 'app/view',
50         );
51
52         /**     @var    array           DB¥¢¥¯¥»¥¹ÄêµÁ */
53         var     $db = array(
54                 ''                              => DB_TYPE_RW,
55         );
56
57         /**     @var    array           ³ÈÄ¥»ÒÀßÄê */
58         var $ext = array(
59                 'php'                   => 'php',
60                 'tpl'                   => 'tpl',
61         );
62
63         /**     @var    array           ¥¯¥é¥¹ÀßÄê */
64         var $class = array(
65                 'class'                 => 'Ethna_ClassFactory',
66                 'backend'               => 'Ethna_Backend',
67                 'config'                => 'Ethna_Config',
68                 'db'                    => 'Ethna_DB',
69                 'error'                 => 'Ethna_ActionError',
70                 'form'                  => 'Ethna_ActionForm',
71                 'i18n'                  => 'Ethna_I18N',
72                 'logger'                => 'Ethna_Logger',
73                 'session'               => 'Ethna_Session',
74                 'sql'                   => 'Ethna_AppSQL',
75                 'view'                  => 'Ethna_ViewClass',
76         );
77
78         /**     @var    array           ¥Õ¥£¥ë¥¿ÀßÄê */
79         var $filter = array(
80         );
81
82         /**     @var    string          »ÈÍѸÀ¸ìÀßÄê */
83         var $language;
84
85         /**     @var    string          ¥·¥¹¥Æ¥à¦¥¨¥ó¥³¡¼¥Ç¥£¥ó¥° */
86         var     $system_encoding;
87
88         /**     @var    string          ¥¯¥é¥¤¥¢¥ó¥È¦¥¨¥ó¥³¡¼¥Ç¥£¥ó¥° */
89         var     $client_encoding;
90
91         /**     @var    string          ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥× */
92         var $client_type;
93
94         /**     @var    string  ¸½ºß¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾ */
95         var     $action_name;
96
97         /**     @var    array   forwardÄêµÁ */
98         var $forward = array();
99
100         /**     @var    array   actionÄêµÁ */
101         var $action = array();
102
103         /**     @var    array   soap actionÄêµÁ */
104         var $soap_action = array();
105
106         /**     @var    array   ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Þ¥Í¡¼¥¸¥ãÄêµÁ */
107         var     $manager = array();
108
109         /**     @var    array   smarty modifierÄêµÁ */
110         var $smarty_modifier_plugin = array();
111
112         /**     @var    array   smarty functionÄêµÁ */
113         var $smarty_function_plugin = array();
114
115         /**     @var    array   smarty prefilterÄêµÁ */
116         var $smarty_prefilter_plugin = array();
117
118         /**     @var    array   smarty postfilterÄêµÁ */
119         var $smarty_postfilter_plugin = array();
120
121         /**     @var    array   smarty outputfilterÄêµÁ */
122         var $smarty_outputfilter_plugin = array();
123
124         /**     @var    array   ¥Õ¥£¥ë¥¿¡¼¥Á¥§¥¤¥ó(Ethna_Filter¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇÛÎó) */
125         var     $filter_chain = array();
126
127         /**     @var    object  Ethna_ClassFactory      ¥¯¥é¥¹¥Õ¥¡¥¯¥È¥ê¥ª¥Ö¥¸¥§¥¯¥È */
128         var     $class_factory = null;
129
130         /**     @var    object  Ethna_ActionForm        ¥Õ¥©¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È */
131         var     $action_form = null;
132
133         /**     @var    object  Ethna_Config            ÀßÄꥪ¥Ö¥¸¥§¥¯¥È */
134         var     $config = null;
135
136         /**     @var    object  Ethna_Logger            ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È */
137         var     $logger = null;
138
139         /**     @var    bool    CLI¥¢¥¯¥·¥ç¥ó¼Â¹ÔÃæ¥Õ¥é¥° */
140         var     $cli    = false;
141
142         /**#@-*/
143
144
145         /**
146          *      Ethna_Controller¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
147          *
148          *      @access         public
149          */
150         function Ethna_Controller()
151         {
152                 $GLOBALS['controller'] =& $this;
153                 $this->base = BASE;
154
155                 // ¥¯¥é¥¹¥Õ¥¡¥¯¥È¥ê¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®
156                 $class_factory = $this->class['class'];
157                 $this->class_factory =& new $class_factory($this, $this->class);
158
159                 // ¥¨¥é¡¼¥Ï¥ó¥É¥é¤ÎÀßÄê
160                 Ethna::setErrorCallback(array(&$this, 'handleError'));
161
162                 // ¥Ç¥£¥ì¥¯¥È¥ê̾¤ÎÀßÄê(ÁêÂХѥ¹->ÀäÂХѥ¹)
163                 foreach ($this->directory as $key => $value) {
164                         if ($key == 'plugins') {
165                                 // Smarty¥×¥é¥°¥¤¥ó¥Ç¥£¥ì¥¯¥È¥ê¤ÏÇÛÎó¤Ç»ØÄꤹ¤ë
166                                 $tmp = array(SMARTY_DIR . 'plugins');
167                                 foreach (to_array($value) as $elt) {
168                                         if (Ethna_Util::isAbsolute($elt) == false) {
169                                                 $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt;
170                                         }
171                                 }
172                                 $this->directory[$key] = $tmp;
173                         } else {
174                                 if (Ethna_Util::isAbsolute($value) == false) {
175                                         $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value;
176                                 }
177                         }
178                 }
179
180                 // ½é´üÀßÄê
181                 list($this->language, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage();
182                 $this->client_type = $this->_getDefaultClientType();
183
184                 $this->config =& $this->getConfig();
185                 $this->dsn = $this->_prepareDSN();
186                 $this->url = $this->config->get('url');
187
188                 // ¥í¥°½ÐÎϳ«»Ï
189                 $this->logger =& $this->getLogger();
190                 $this->logger->begin();
191
192                 // Ethna¥Þ¥Í¡¼¥¸¥ãÀßÄê
193                 $this->_activateEthnaManager();
194         }
195
196         /**
197          *      (¸½ºß¥¢¥¯¥Æ¥£¥Ö¤Ê)¥³¥ó¥È¥í¡¼¥é¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òÊÖ¤¹
198          *
199          *      @access public
200          *      @return object  Ethna_Controller        ¥³¥ó¥È¥í¡¼¥é¤Î¥¤¥ó¥¹¥¿¥ó¥¹
201          *      @static
202          */
203         function &getInstance()
204         {
205                 if (isset($GLOBALS['controller'])) {
206                         return $GLOBALS['controller'];
207                 } else {
208                         return null;
209                 }
210         }
211
212         /**
213          *      ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID¤òÊÖ¤¹
214          *
215          *      @access public
216          *      @return string  ¥¢¥×¥ê¥±¡¼¥·¥ç¥óID
217          */
218         function getAppId()
219         {
220                 return ucfirst(strtolower($this->appid));
221         }
222
223         /**
224          *      DSN¤òÊÖ¤¹
225          *
226          *      @access public
227          *      @param  string  $type   DB¼ïÊÌ
228          *      @return string  DSN
229          */
230         function getDSN($type = "")
231         {
232                 if (isset($this->dsn[$type]) == false) {
233                         return null;
234                 }
235                 return $this->dsn[$type];
236         }
237
238         /**
239          *      DSN¤Î»ý³ÀܳÀßÄê¤òÊÖ¤¹
240          *
241          *      @access public
242          *      @param  string  $type   DB¼ïÊÌ
243          *      @return bool    true:persistent false:non-persistent(¤¢¤ë¤¤¤ÏÀßÄê̵¤·)
244          */
245         function getDSN_persistent($type = "")
246         {
247                 $key = sprintf("dsn%s_persistent", $type == "" ? "" : "_$type");
248
249                 $dsn_persistent = $this->config->get($key);
250                 if (is_null($dsn_persistent)) {
251                         return false;
252                 }
253                 return $dsn_persistent;
254         }
255
256         /**
257          *      ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL¤òÊÖ¤¹
258          *
259          *      @access public
260          *      @return string  ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹URL
261          */
262         function getURL()
263         {
264                 return $this->url;
265         }
266
267         /**
268          *      ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê¤òÊÖ¤¹
269          *
270          *      @access public
271          *      @return string  ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ù¡¼¥¹¥Ç¥£¥ì¥¯¥È¥ê
272          */
273         function getBasedir()
274         {
275                 return $this->base;
276         }
277
278         /**
279          *      ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×/¸À¸ì¤«¤é¥Æ¥ó¥×¥ì¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
280          *
281          *      @access public
282          *      @return string  ¥Æ¥ó¥×¥ì¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê
283          */
284         function getTemplatedir()
285         {
286                 $template = $this->getDirectory('template');
287
288                 // ¸À¸ìÊ̥ǥ£¥ì¥¯¥È¥ê
289                 if (file_exists($template . '/' . $this->language)) {
290                         $template .= '/' . $this->language;
291                 }
292
293                 // ¥¯¥é¥¤¥¢¥ó¥ÈÊ̥ǥ£¥ì¥¯¥È¥ê(if we need)
294                 if ($this->client_type == CLIENT_TYPE_MOBILE_AU && file_exists($template . '/au')) {
295                         $template .= '/au';
296                 }
297
298                 return $template;
299         }
300
301         /**
302          *      ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
303          *
304          *      @access public
305          *      @return string  ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
306          */
307         function getActiondir()
308         {
309                 return (empty($this->directory['action']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['action'] . "/"));
310         }
311
312         /**
313          *      ¥Ó¥å¡¼¥Ç¥£¥ì¥¯¥È¥ê̾¤ò·èÄꤹ¤ë
314          *
315          *      @access public
316          *      @return string  ¥¢¥¯¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê
317          */
318         function getViewdir()
319         {
320                 return (empty($this->directory['view']) ? ($this->base . (empty($this->base) ? '' : '/')) : ($this->directory['view'] . "/"));
321         }
322
323         /**
324          *      ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥êÀßÄê¤òÊÖ¤¹
325          *
326          *      @access public
327          *      @param  string  $key    ¥Ç¥£¥ì¥¯¥È¥ê¥¿¥¤¥×("tmp", "template"...)
328          *      @return string  $key¤ËÂбþ¤·¤¿¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥Ç¥£¥ì¥¯¥È¥ê(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
329          */
330         function getDirectory($key)
331         {
332                 if (isset($this->directory[$key]) == false) {
333                         return null;
334                 }
335                 return $this->directory[$key];
336         }
337
338         /**
339          *      DBÀßÄê¤òÊÖ¤¹
340          *
341          *      @access public
342          *      @param  string  $key    DB¥¿¥¤¥×("r", ...)
343          *      @return string  $key¤ËÂбþ¤¹¤ëDB¼ïÊÌÄêµÁ(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
344          */
345         function getDB($key)
346         {
347                 if (isset($this->db[$key]) == false) {
348                         return null;
349                 }
350                 return $this->db[$key];
351         }
352
353         /**
354          *      ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó³ÈÄ¥»ÒÀßÄê¤òÊÖ¤¹
355          *
356          *      @access public
357          *      @param  string  $key    ³ÈÄ¥»Ò¥¿¥¤¥×("php", "tpl"...)
358          *      @return string  $key¤ËÂбþ¤·¤¿³ÈÄ¥»Ò(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
359          */
360         function getExt($key)
361         {
362                 if (isset($this->ext[$key]) == false) {
363                         return null;
364                 }
365                 return $this->ext[$key];
366         }
367
368         /**
369          *      ¥¯¥é¥¹¥Õ¥¡¥¯¥È¥ê¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ(R)
370          *
371          *      @access public
372          *      @return object  Ethna_ClassFactory      ¥¯¥é¥¹¥Õ¥¡¥¯¥È¥ê¥ª¥Ö¥¸¥§¥¯¥È
373          */
374         function &getClassFactory()
375         {
376                 return $this->class_factory;
377         }
378
379         /**
380          *      ¥¢¥¯¥·¥ç¥ó¥¨¥é¡¼¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
381          *
382          *      @access public
383          *      @return object  Ethna_ActionError       ¥¢¥¯¥·¥ç¥ó¥¨¥é¡¼¥ª¥Ö¥¸¥§¥¯¥È
384          */
385         function &getActionError()
386         {
387                 return $this->class_factory->getObject('error');
388         }
389
390         /**
391          *      ¥¢¥¯¥·¥ç¥ó¥Õ¥©¡¼¥àform¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
392          *
393          *      @access public
394          *      @return object  Ethna_ActionForm        ¥¢¥¯¥·¥ç¥ó¥Õ¥©¡¼¥àform¥ª¥Ö¥¸¥§¥¯¥È
395          */
396         function &getActionForm()
397         {
398                 // ÌÀ¼¨Åª¤Ë¥¯¥é¥¹¥Õ¥¡¥¯¥È¥ê¤òÍøÍѤ·¤Æ¤¤¤Ê¤¤
399                 return $this->action_form;
400         }
401
402         /**
403          *      backend¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
404          *
405          *      @access public
406          *      @return object  Ethna_Backend   backend¥ª¥Ö¥¸¥§¥¯¥È
407          */
408         function &getBackend()
409         {
410                 return $this->class_factory->getObject('backend');
411         }
412
413         /**
414          *      ÀßÄꥪ¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
415          *
416          *      @access public
417          *      @return object  Ethna_Config    ÀßÄꥪ¥Ö¥¸¥§¥¯¥È
418          */
419         function &getConfig()
420         {
421                 return $this->class_factory->getObject('config');
422         }
423
424         /**
425          *      i18n¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ(R)
426          *
427          *      @access public
428          *      @return object  Ethna_I18N      i18n¥ª¥Ö¥¸¥§¥¯¥È
429          */
430         function &getI18N()
431         {
432                 return $this->class_factory->getObject('i18n');
433         }
434
435         /**
436          *      ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
437          *
438          *      @access public
439          *      @return object  Ethna_Logger            ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È
440          */
441         function &getLogger()
442         {
443                 return $this->class_factory->getObject('logger');
444         }
445
446         /**
447          *      ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
448          *
449          *      @access public
450          *      @return object  Ethna_Session           ¥»¥Ã¥·¥ç¥ó¥ª¥Ö¥¸¥§¥¯¥È
451          */
452         function &getSession()
453         {
454                 return $this->class_factory->getObject('session');
455         }
456
457         /**
458          *      SQL¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¢¥¯¥»¥µ
459          *
460          *      @access public
461          *      @return object  Ethna_AppSQL    SQL¥ª¥Ö¥¸¥§¥¯¥È
462          */
463         function &getSQL()
464         {
465                 return $this->class_factory->getObject('sql');
466         }
467
468         /**
469          *      ¥Þ¥Í¡¼¥¸¥ã°ìÍ÷¤òÊÖ¤¹
470          *
471          *      @access public
472          *      @return array   ¥Þ¥Í¡¼¥¸¥ã°ìÍ÷
473          */
474         function getManagerList()
475         {
476                 return $this->manager;
477         }
478
479         /**
480          *      ¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
481          *
482          *      @access public
483          *      @return string  ¼Â¹ÔÃæ¤Î¥¢¥¯¥·¥ç¥ó̾
484          */
485         function getCurrentActionName()
486         {
487                 return $this->action_name;
488         }
489
490         /**
491          *      »ÈÍѸÀ¸ì¤ò¼èÆÀ¤¹¤ë
492          *
493          *      @access public
494          *      @return array   »ÈÍѸÀ¸ì,¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾,¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
495          */
496         function getLanguage()
497         {
498                 return array($this->language, $this->system_encoding, $this->client_encoding);
499         }
500
501         /**
502          *      ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤ò¼èÆÀ¤¹¤ë
503          *
504          *      @access public
505          *      @return int             ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
506          */
507         function getClientType()
508         {
509                 return $this->client_type;
510         }
511
512         /**
513          *      ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤òÀßÄꤹ¤ë
514          *
515          *      @access public
516          *      @param  int             $client_type    ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
517          */
518         function setClientType($client_type)
519         {
520                 $this->client_type = $client_type;
521         }
522
523         /**
524          *      CLI¼Â¹ÔÃæ¥Õ¥é¥°¤ò¼èÆÀ¤¹¤ë
525          *
526          *      @access public
527          *      @return bool    CLI¼Â¹ÔÃæ¥Õ¥é¥°
528          */
529         function getCLI()
530         {
531                 return $this->cli;
532         }
533
534         /**
535          *      CLI¼Â¹ÔÃæ¥Õ¥é¥°¤òÀßÄꤹ¤ë
536          *
537          *      @access public
538          *      @param  bool    CLI¼Â¹ÔÃæ¥Õ¥é¥°
539          */
540         function setCLI($cli)
541         {
542                 $this->cli = $cli;
543         }
544
545         /**
546          *      ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
547          *
548          *      @access public
549          *      @param  string  $class_name             ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
550          *      @param  mixed   $action_name    »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾(¾Êά²Ä)
551          *      @param  mixed   $fallback_action_name   ¥¢¥¯¥·¥ç¥ó¤¬·èÄê¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾(¾Êά²Ä)
552          *      @static
553          */
554         function main($class_name, $action_name = "", $fallback_action_name = "")
555         {
556                 $c =& new $class_name;
557                 $c->trigger('www', $action_name, $fallback_action_name);
558         }
559
560         /**
561          *      ¥³¥Þ¥ó¥É¥é¥¤¥ó¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
562          *
563          *      @access public
564          *      @param  string  $class_name             ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
565          *      @param  string  $action_name    ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾
566          *      @static
567          */
568         function main_CLI($class_name, $action_name)
569         {
570                 $c =& new $class_name;
571                 $c->setCLI(true);
572                 $c->action[$action_name] = array();
573                 $c->trigger('www', $action_name);
574         }
575
576         /**
577          *      SOAP¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
578          *
579          *      @access public
580          *      @param  string  $class_name     ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
581          *      @static
582          */
583         function main_SOAP($class_name)
584         {
585                 $c =& new $class_name;
586                 $c->setClientType(CLIENT_TYPE_SOAP);
587                 $c->trigger('soap');
588         }
589
590         /**
591          *      AMF(Flash Remoting)¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È
592          *
593          *      @access public
594          *      @param  string  $class_name     ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥³¥ó¥È¥í¡¼¥é¤Î¥¯¥é¥¹Ì¾
595          *      @static
596          */
597         function main_AMF($class_name)
598         {
599                 $c =& new $class_name;
600                 $c->setClientType(CLIENT_TYPE_AMF);
601                 $c->trigger('amf');
602         }
603
604         /**
605          *      ¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò³«»Ï¤¹¤ë
606          *
607          *      @access public
608          *      @param  strint  $type                                   ½èÍý¥¿¥¤¥×(WWW/SOAP/AMF)
609          *      @param  mixed   $default_action_name    »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾
610          *      @param  mixed   $fallback_action_name   ¥¢¥¯¥·¥ç¥ó̾¤¬·èÄê¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾
611          *      @return mixed   0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
612          */
613         function trigger($type, $default_action_name = "", $fallback_action_name = "")
614         {
615                 // ¥Õ¥£¥ë¥¿¡¼¤ÎÀ¸À®
616                 $this->_createFilterChain();
617
618                 // ¼Â¹ÔÁ°¥Õ¥£¥ë¥¿
619                 for ($i = 0; $i < count($this->filter_chain); $i++) {
620                         $this->filter_chain[$i]->preFilter();
621                 }
622
623                 // trigger
624                 if ($type == 'www') {
625                         $this->_trigger($default_action_name, $fallback_action_name);
626                 } else if ($type == 'soap') {
627                         $this->_trigger_SOAP();
628                 } else if ($type == 'amf') {
629                         $this->_trigger_AMF();
630                 }
631
632                 // ¼Â¹Ô¸å¥Õ¥£¥ë¥¿
633                 for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
634                         $this->filter_chain[$i]->postFilter();
635                 }
636         }
637
638         /**
639          *      ¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò¼Â¹Ô¤¹¤ë(WWW)
640          *
641          *      °ú¿ô$default_action_name¤ËÇÛÎ󤬻ØÄꤵ¤ì¤¿¾ì¹ç¡¢¤½¤ÎÇÛÎó¤Ç»ØÄꤵ¤ì¤¿
642          *      ¥¢¥¯¥·¥ç¥ó°Ê³°¤Ï¼õ¤±ÉÕ¤±¤Ê¤¤(¤½¤ì°Ê³°¤Î¥¢¥¯¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
643          *      ÇÛÎó¤ÎÀèƬ¤Ç»ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤¬¼Â¹Ô¤µ¤ì¤ë)
644          *
645          *      @access private
646          *      @param  mixed   $default_action_name    »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾
647          *      @param  mixed   $fallback_action_name   ¥¢¥¯¥·¥ç¥ó̾¤¬·èÄê¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¼Â¹Ô¤µ¤ì¤ë¥¢¥¯¥·¥ç¥ó̾
648          *      @return mixed   0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
649          */
650         function _trigger($default_action_name = "", $fallback_action_name = "")
651         {
652                 // ¥¢¥¯¥·¥ç¥ó̾¤Î¼èÆÀ
653                 $action_name = $this->_getActionName($default_action_name, $fallback_action_name);
654
655                 // ¥¢¥¯¥·¥ç¥óÄêµÁ¤Î¼èÆÀ
656                 $action_obj =& $this->_getAction($action_name);
657                 if (is_null($action_obj)) {
658                         if ($fallback_action_name != "") {
659                                 $this->logger->log(LOG_DEBUG, 'undefined action [%s] -> try fallback action [%s]', $action_name, $fallback_action_name);
660                                 $action_obj =& $this->_getAction($fallback_action_name);
661                         }
662                         if ($action_obj == null) {
663                                 return Ethna::raiseError("undefined action [%s]", E_APP_UNDEFINED_ACTION, $action_name);
664                         } else {
665                                 $action_name = $fallback_action_name;
666                         }
667                 }
668
669                 // ¥¢¥¯¥·¥ç¥ó¼Â¹ÔÁ°¥Õ¥£¥ë¥¿
670                 for ($i = 0; $i < count($this->filter_chain); $i++) {
671                         $r = $this->filter_chain[$i]->preActionFilter($action_name);
672                         if ($r != null) {
673                                 $this->logger->log(LOG_DEBUG, 'action [%s] -> [%s] by %s', $action_name, $r, get_class($this->filter_chain[$i]));
674                                 $action_name = $r;
675                         }
676                 }
677                 $this->action_name = $action_name;
678
679                 // ¸À¸ìÀßÄê
680                 $this->_setLanguage($this->language, $this->system_encoding, $this->client_encoding);
681
682                 // ¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®
683                 $form_name = $this->getActionFormName($action_name);
684                 $this->action_form =& new $form_name($this);
685
686                 // ¥Ð¥Ã¥¯¥¨¥ó¥É½èÍý¼Â¹Ô
687                 $backend =& $this->getBackend();
688                 $forward_name = $backend->perform($action_name);
689
690                 // ¥¢¥¯¥·¥ç¥ó¼Â¹Ô¸å¥Õ¥£¥ë¥¿
691                 for ($i = count($this->filter_chain) - 1; $i >= 0; $i--) {
692                         $r = $this->filter_chain[$i]->postActionFilter($action_name, $forward_name);
693                         if ($r != null) {
694                                 $this->logger->log(LOG_DEBUG, 'forward [%s] -> [%s] by %s', $forward_name, $r, get_class($this->filter_chain[$i]));
695                                 $forward_name = $r;
696                         }
697                 }
698
699                 // ¥³¥ó¥È¥í¡¼¥é¤ÇÁ«°ÜÀè¤ò·èÄꤹ¤ë(¥ª¥×¥·¥ç¥ó)
700                 $forward_name = $this->_sortForward($action_name, $forward_name);
701
702                 if ($forward_name != null) {
703                         $view_class_name = $this->getViewClassName($forward_name);
704                         $view_class =& new $view_class_name($backend, $forward_name, $this->_getForwardPath($forward_name));
705                         $view_class->preforward();
706
707                         // ¸åÊý¸ß´¹½èÍý:(
708                         $view_class_name = $this->class_factory->getObjectName('view');
709                         if (is_subclass_of($view_class, $view_class_name) == false) {
710                                 $view_class =& new $view_class_name($backend, $forward_name, $this->_getForwardPath($forward_name));
711                         }
712                         $view_class->forward();
713                 }
714
715                 return 0;
716         }
717
718         /**
719          *  SOAP¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò¼Â¹Ô¤¹¤ë
720          *
721          *      (experimental)
722          *
723          *  @access private
724          */
725         function _trigger_SOAP()
726         {
727                 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É
728                 $this->_includeActionScript();
729
730                 // SOAP¥¨¥ó¥È¥ê¥¯¥é¥¹
731                 $gg =& new Ethna_SoapGatewayGenerator();
732                 $script = $gg->generate();
733                 eval($script);
734
735                 // SOAP¥ê¥¯¥¨¥¹¥È½èÍý
736                 $server =& new SoapServer(null, array('uri' => $this->config->get('url')));
737                 $server->setClass($gg->getClassName());
738                 $server->handle();
739         }
740
741         /**
742          *      AMF(Flash Remoting)¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤Î½èÍý¤ò¼Â¹Ô¤¹¤ë
743          *
744          *      (experimental)
745          *
746          *      @access public
747          */
748         function _trigger_AMF()
749         {
750                 include_once('Ethna/contrib/amfphp/app/Gateway.php');
751
752                 // Credential¥Ø¥Ã¥À¤Ç¥»¥Ã¥·¥ç¥ó¤ò½èÍý¤¹¤ë¤Î¤Ç¤³¤³¤Ç¤Ïnull¤ËÀßÄê
753                 $this->session = null;
754
755                 $this->_setLanguage($this->language, $this->system_encoding, $this->client_encoding);
756
757                 // backend¥ª¥Ö¥¸¥§¥¯¥È
758                 $backend =& $this->getBackend();
759
760                 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É
761                 $this->_includeActionScript();
762
763                 // amfphp¤Ë½èÍý¤ò°Ñ¾ù
764                 $gateway =& new Gateway();
765                 $gateway->setBaseClassPath('');
766                 $gateway->service();
767         }
768
769         /**
770          *      ¥¨¥é¡¼¥Ï¥ó¥É¥é
771          *
772          *      ¥¨¥é¡¼È¯À¸»þ¤ÎÄɲýèÍý¤ò¹Ô¤¤¤¿¤¤¾ì¹ç¤Ï¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
773          *      (¥¢¥é¡¼¥È¥á¡¼¥ëÁ÷¿®Åù¡Ý¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¥í¥°½ÐÎÏ»þ¤Ë¥¢¥é¡¼¥È¥á¡¼¥ë
774          *      ¤¬Á÷¿®¤µ¤ì¤ë¤¬¡¢¥¨¥é¡¼È¯À¸»þ¤ËÊ̤˥¢¥é¡¼¥È¥á¡¼¥ë¤ò¤³¤³¤ÇÁ÷¿®
775          *      ¤µ¤»¤ë¤³¤È¤â²Äǽ)
776          *
777          *      @access public
778          *      @param  object  Ethna_Error             ¥¨¥é¡¼¥ª¥Ö¥¸¥§¥¯¥È
779          */
780         function handleError(&$error)
781         {
782                 // ¥í¥°½ÐÎÏ
783                 list ($log_level, $dummy) = $this->logger->errorLevelToLogLevel($error->getLevel());
784                 $message = $error->getMessage();
785                 $this->logger->log($log_level, sprintf("%s [ERROR CODE(%d)]", $message, $error->getCode()));
786         }
787
788         /**
789          *      ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ò¼èÆÀ¤¹¤ë
790          *
791          *      @access public
792          *      @param  int             $code           ¥¨¥é¡¼¥³¡¼¥É
793          *      @return string  ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
794          */
795         function getErrorMessage($code)
796         {
797                 $message_list =& $GLOBALS['_Ethna_error_message_list'];
798                 for ($i = count($message_list)-1; $i >= 0; $i--) {
799                         if (array_key_exists($code, $message_list[$i])) {
800                                 return $message_list[$i][$code];
801                         }
802                 }
803                 return null;
804         }
805
806         /**
807          *      ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
808          *
809          *      @access private
810          *      @param  mixed   $default_action_name    »ØÄê¤Î¥¢¥¯¥·¥ç¥ó̾
811          *      @return string  ¼Â¹Ô¤¹¤ë¥¢¥¯¥·¥ç¥ó̾
812          */
813         function _getActionName($default_action_name, $fallback_action_name)
814         {
815                 // ¥Õ¥©¡¼¥à¤«¤éÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤ò¼èÆÀ¤¹¤ë
816                 $form_action_name = $this->_getActionName_Form();
817                 $form_action_name = preg_replace('/[^a-z0-9\-_]+/i', '', $form_action_name);
818                 $this->logger->log(LOG_DEBUG, 'form_action_name[%s]', $form_action_name);
819
820                 // Ethna¥Þ¥Í¡¼¥¸¥ã¤Ø¤Î¥Õ¥©¡¼¥à¤«¤é¤Î¥ê¥¯¥¨¥¹¥È¤ÏµñÈÝ
821                 if ($form_action_name == "__ethna_info__") {
822                         $form_action_name = "";
823                 }
824
825                 // ¥Õ¥©¡¼¥à¤«¤é¤Î»ØÄ̵꤬¤¤¾ì¹ç¤Ï¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È¤Ë»ØÄꤵ¤ì¤¿¥Ç¥Õ¥©¥ë¥ÈÃͤòÍøÍѤ¹¤ë
826                 if ($form_action_name == "" && count($default_action_name) > 0) {
827                         $tmp = is_array($default_action_name) ? $default_action_name[0] : $default_action_name;
828                         if ($tmp{strlen($tmp)-1} == '*') {
829                                 $tmp = substr($tmp, 0, -1);
830                         }
831                         $this->logger->log(LOG_DEBUG, '-> default_action_name[%s]', $tmp);
832                         $action_name = $tmp;
833                 } else {
834                         $action_name = $form_action_name;
835                 }
836
837                 // ¥¨¥ó¥È¥ê¥Ý¥¤¥ó¥È¤ËÇÛÎ󤬻ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï»ØÄê°Ê³°¤Î¥¢¥¯¥·¥ç¥ó̾¤ÏµñÈݤ¹¤ë
838                 if (is_array($default_action_name)) {
839                         if ($this->_isAcceptableActionName($action_name, $default_action_name) == false) {
840                                 // »ØÄê°Ê³°¤Î¥¢¥¯¥·¥ç¥ó̾¤Ç¹ç¤Ã¤¿¾ì¹ç¤Ï$fallback_action_name(or ¥Ç¥Õ¥©¥ë¥È)
841                                 $tmp = $fallback_action_name != "" ? $fallback_action_name : $default_action_name[0];
842                                 if ($tmp{strlen($tmp)-1} == '*') {
843                                         $tmp = substr($tmp, 0, -1);
844                                 }
845                                 $this->logger->log(LOG_DEBUG, '-> fallback_action_name[%s]', $tmp);
846                                 $action_name = $tmp;
847                         }
848                 }
849
850                 $this->logger->log(LOG_DEBUG, '<<< action_name[%s] >>>', $action_name);
851
852                 return $action_name;
853         }
854
855         /**
856          *      ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤òÊÖ¤¹
857          *
858          *      ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÎÀ­¼Á¤Ë±þ¤¸¤Æ¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤Æ²¼¤µ¤¤¡£
859          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"action_"¤Ç»Ï¤Þ¤ë¥Õ¥©¡¼¥àÃͤÎ"action_"¤ÎÉôʬ¤ò½ü¤¤¤¿¤â¤Î
860          *      ("action_sample"¤Ê¤é"sample")¤¬¥¢¥¯¥·¥ç¥ó̾¤È¤·¤Æ°·¤ï¤ì¤Þ¤¹
861          *
862          *      @access protected
863          *      @return string  ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾
864          */
865         function _getActionName_Form()
866         {
867                 if (isset($_SERVER['REQUEST_METHOD']) == false) {
868                         return null;
869                 }
870
871                 if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
872                         $http_vars =& $_POST;
873                 } else {
874                         $http_vars =& $_GET;
875                 }
876
877                 // ¥Õ¥©¡¼¥àÃͤ«¤é¥ê¥¯¥¨¥¹¥È¤µ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤ò¼èÆÀ¤¹¤ë
878                 $action_name = $sub_action_name = null;
879                 foreach ($http_vars as $name => $value) {
880                         if ($value == "" || strncmp($name, 'action_', 7) != 0) {
881                                 continue;
882                         }
883
884                         $tmp = substr($name, 7);
885
886                         // type="image"Âбþ
887                         if (preg_match('/_x$/', $name) || preg_match('/_y$/', $name)) {
888                                 $tmp = substr($tmp, 0, strlen($tmp)-2);
889                         }
890
891                         // value="dummy"¤È¤Ê¤Ã¤Æ¤¤¤ë¤â¤Î¤ÏÍ¥ÀèÅÙ¤ò²¼¤²¤ë
892                         if ($value == "dummy") {
893                                 $sub_action_name = $tmp;
894                         } else {
895                                 $action_name = $tmp;
896                         }
897                 }
898                 if ($action_name == null) {
899                         $action_name = $sub_action_name;
900                 }
901
902                 return $action_name;
903         }
904
905         /**
906          *      ¥Õ¥©¡¼¥à¤Ë¤è¤êÍ׵ᤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾¤ËÂбþ¤¹¤ëÄêµÁ¤òÊÖ¤¹
907          *
908          *      @access private
909          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
910          *      @return array   ¥¢¥¯¥·¥ç¥óÄêµÁ
911          */
912         function &_getAction($action_name)
913         {
914                 if ($this->client_type == CLIENT_TYPE_SOAP) {
915                         $action =& $this->soap_action;
916                 } else {
917                         $action =& $this->action;
918                 }
919
920                 $action_obj = array();
921                 if (isset($action[$action_name])) {
922                         $action_obj = $action[$action_name];
923                         if (isset($action_obj['inspect']) && $action_obj['inspect']) {
924                                 return $action_obj;
925                         }
926                 } else {
927                         $this->logger->log(LOG_DEBUG, "action [%s] is not defined -> try default", $action_name);
928                 }
929
930                 // ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤Î¥¤¥ó¥¯¥ë¡¼¥É
931                 $this->_includeActionScript($action_obj, $action_name);
932
933                 // ¾ÊάÃͤÎÊäÀµ
934                 if (isset($action_obj['class_name']) == false) {
935                         $action_obj['class_name'] = $this->getDefaultActionClass($action_name);
936                 }
937
938                 if (isset($action_obj['form_name']) == false) {
939                         $action_obj['form_name'] = $this->getDefaultFormClass($action_name);
940                 } else if (class_exists($action_obj['form_name']) == false) {
941                         // ÌÀ¼¨»ØÄꤵ¤ì¤¿¥Õ¥©¡¼¥à¥¯¥é¥¹¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï·Ù¹ð
942                         $this->logger->log(LOG_WARNING, 'stated form class is not defined [%s]', $action_obj['form_name']);
943                 }
944
945                 // É¬Í×¾ò·ï¤Î³Îǧ
946                 if (class_exists($action_obj['class_name']) == false) {
947                         $this->logger->log(LOG_WARNING, 'action class is not defined [%s]', $action_obj['class_name']);
948                         return null;
949                 }
950                 if (class_exists($action_obj['form_name']) == false) {
951                         // ¥Õ¥©¡¼¥à¥¯¥é¥¹¤Ï̤ÄêµÁ¤Ç¤âÎɤ¤
952                         $class_name = $this->class_factory->getObjectName('form');
953                         $this->logger->log(LOG_DEBUG, 'form class is not defined [%s] -> falling back to default [%s]', $action_obj['form_name'], $class_name);
954                         $action_obj['form_name'] = $class_name;
955                 }
956
957                 $action_obj['inspect'] = true;
958                 $action[$action_name] = $action_obj;
959                 return $action[$action_name];
960         }
961
962         /**
963          *      ¥¢¥¯¥·¥ç¥ó̾¤È¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤«¤é¤ÎÌá¤êÃͤ˴ð¤Å¤¤¤ÆÁ«°ÜÀè¤ò·èÄꤹ¤ë
964          *
965          *      @access protected
966          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
967          *      @param  string  $retval                 ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤«¤é¤ÎÌá¤êÃÍ
968          *      @return string  Á«°ÜÀè
969          */
970         function _sortForward($action_name, $retval)
971         {
972                 return $retval;
973         }
974
975         /**
976          *      ¥Õ¥£¥ë¥¿¡¼¥Á¥§¥¤¥ó¤òÀ¸À®¤¹¤ë
977          *
978          *      @access private
979          */
980         function _createFilterChain()
981         {
982                 $this->filter_chain = array();
983                 foreach ($this->filter as $filter) {
984                         $file = sprintf("%s/%s.%s", $this->getDirectory('filter'), $filter, $this->getExt('php'));
985                         if (file_exists($file)) {
986                                 include_once($file);
987                         }
988                         if (class_exists($filter)) {
989                                 $this->filter_chain[] =& new $filter($this);
990                         }
991                 }
992         }
993
994         /**
995          *      ¥¢¥¯¥·¥ç¥ó̾¤¬¼Â¹Ôµö²Ä¤µ¤ì¤Æ¤¤¤ë¤â¤Î¤«¤É¤¦¤«¤òÊÖ¤¹
996          *
997          *      @access private
998          *      @param  string  $action_name                    ¥ê¥¯¥¨¥¹¥È¤µ¤ì¤¿¥¢¥¯¥·¥ç¥ó̾
999          *      @param  array   $default_action_name    µö²Ä¤µ¤ì¤Æ¤¤¤ë¥¢¥¯¥·¥ç¥ó̾
1000          *      @return bool    true:µö²Ä false:ÉÔµö²Ä
1001          */
1002         function _isAcceptableActionName($action_name, $default_action_name)
1003         {
1004                 foreach (to_array($default_action_name) as $name) {
1005                         if ($action_name == $name) {
1006                                 return true;
1007                         } else if ($name{strlen($name)-1} == '*') {
1008                                 if (strncmp($action_name, substr($name, 0, -1), strlen($name)-1) == 0) {
1009                                         return true;
1010                                 }
1011                         }
1012                 }
1013                 return false;
1014         }
1015
1016         /**
1017          *      »ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Î¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
1018          *
1019          *      @access public
1020          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
1021          *      @return string  ¥¢¥¯¥·¥ç¥ó¤Î¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾
1022          */
1023         function getActionFormName($action_name)
1024         {
1025                 $action_obj =& $this->_getAction($action_name);
1026                 if (is_null($action_obj)) {
1027                         return null;
1028                 }
1029
1030                 return $action_obj['form_name'];
1031         }
1032
1033         /**
1034          *      ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
1035          *
1036          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_Form_[¥¢¥¯¥·¥ç¥ó̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1037          *
1038          *      @access public
1039          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
1040          *      @param  bool    $fallback               ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1041          *      @return string  ¥¢¥¯¥·¥ç¥ó¥Õ¥©¡¼¥à̾
1042          */
1043         function getDefaultFormClass($action_name, $fallback = true)
1044         {
1045                 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
1046
1047                 $r = null;
1048                 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
1049                         $r = sprintf("%s_SOAPForm_%s", $this->getAppId(), $postfix);
1050                 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1051                         $tmp = sprintf("%s_MobileAUForm_%s", $this->getAppId(), $postfix);
1052                         if ($fallback == false || class_exists($tmp)) {
1053                                 $r = $tmp;
1054                         }
1055                 }
1056
1057                 if ($r == null) {
1058                         $r = sprintf("%s_Form_%s", $this->getAppId(), $postfix);
1059                 }
1060                 $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1061                 return $r;
1062         }
1063
1064         /**
1065          *      getDefaultFormClass()¤Ç¼èÆÀ¤·¤¿¥¯¥é¥¹Ì¾¤«¤é¥¢¥¯¥·¥ç¥ó̾¤ò¼èÆÀ¤¹¤ë
1066          *
1067          *      getDefaultFormClass()¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤¿¾ì¹ç¡¢¤³¤Á¤é¤â¹ç¤ï¤»¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É
1068          *      ¤¹¤ë¤³¤È¤ò¿ä¾©(ɬ¿Ü¤Ç¤Ï¤Ê¤¤)
1069          *
1070          *      @access public
1071          *      @param  string  $class_name             ¥Õ¥©¡¼¥à¥¯¥é¥¹Ì¾
1072          *      @return string  ¥¢¥¯¥·¥ç¥ó̾
1073          */
1074         function actionFormToName($class_name)
1075         {
1076                 $prefix = sprintf("%s_Form_", $this->getAppId());
1077                 if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
1078                         // ÉÔÌÀ¤Ê¥¯¥é¥¹Ì¾
1079                         return null;
1080                 }
1081                 $target = $match[1];
1082
1083                 $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
1084
1085                 return $action_name;
1086         }
1087
1088         /**
1089          *      ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥Õ¥©¡¼¥à¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1090          *
1091          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï_getDefaultActionPath()¤ÈƱ¤¸·ë²Ì¤òÊÖ¤¹(1¥Õ¥¡¥¤¥ë¤Ë
1092          *      ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤È¥Õ¥©¡¼¥à¥¯¥é¥¹¤¬µ­½Ò¤µ¤ì¤ë)¤Î¤Ç¡¢¹¥¤ß¤Ë±þ¤¸¤Æ
1093          *      ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1094          *
1095          *      @access public
1096          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
1097          *      @param  bool    $fallback               ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1098          *      @return string  form class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1099          */
1100         function getDefaultFormPath($action_name, $fallback = true)
1101         {
1102                 return $this->getDefaultActionPath($action_name, $fallback);
1103         }
1104
1105         /**
1106          *      »ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Î¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
1107          *
1108          *      @access public
1109          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó¤Î̾¾Î
1110          *      @return string  ¥¢¥¯¥·¥ç¥ó¤Î¥¯¥é¥¹Ì¾
1111          */
1112         function getActionClassName($action_name)
1113         {
1114                 $action_obj =& $this->_getAction($action_name);
1115                 if ($action_obj == null) {
1116                         return null;
1117                 }
1118
1119                 return $action_obj['class_name'];
1120         }
1121
1122         /**
1123          *      ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
1124          *
1125          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_Action_[¥¢¥¯¥·¥ç¥ó̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1126          *
1127          *      @access public
1128          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
1129          *      @param  bool    $fallback               ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1130          *      @return string  ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹Ì¾
1131          */
1132         function getDefaultActionClass($action_name, $fallback = true)
1133         {
1134                 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($action_name));
1135
1136                 $r = null;
1137                 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
1138                         $r = sprintf("%s_SOAPAction_%s", $this->getAppId(), $postfix);
1139                 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1140                         $tmp = sprintf("%s_MobileAUAction_%s", $this->getAppId(), $postfix);
1141                         if ($fallback == false || class_exists($tmp)) {
1142                                 $r = $tmp;
1143                         }
1144                 }
1145
1146                 if ($r == null) {
1147                         $r = sprintf("%s_Action_%s", $this->getAppId(), $postfix);
1148                 }
1149                 $this->logger->log(LOG_DEBUG, "default action class [%s]", $r);
1150                 return $r;
1151         }
1152
1153         /**
1154          *      getDefaultActionClass()¤Ç¼èÆÀ¤·¤¿¥¯¥é¥¹Ì¾¤«¤é¥¢¥¯¥·¥ç¥ó̾¤ò¼èÆÀ¤¹¤ë
1155          *
1156          *      getDefaultActionClass()¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤¿¾ì¹ç¡¢¤³¤Á¤é¤â¹ç¤ï¤»¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É
1157          *      ¤¹¤ë¤³¤È¤ò¿ä¾©(ɬ¿Ü¤Ç¤Ï¤Ê¤¤)
1158          *
1159          *      @access public
1160          *      @param  string  $class_name             ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹Ì¾
1161          *      @return string  ¥¢¥¯¥·¥ç¥ó̾
1162          */
1163         function actionClassToName($class_name)
1164         {
1165                 $prefix = sprintf("%s_Action_", $this->getAppId());
1166                 if (preg_match("/$prefix(.*)/", $class_name, $match) == 0) {
1167                         // ÉÔÌÀ¤Ê¥¯¥é¥¹Ì¾
1168                         return null;
1169                 }
1170                 $target = $match[1];
1171
1172                 $action_name = substr(preg_replace('/([A-Z])/e', "'_' . strtolower('\$1')", $target), 1);
1173
1174                 return $action_name;
1175         }
1176
1177         /**
1178          *      ¥¢¥¯¥·¥ç¥ó¤ËÂбþ¤¹¤ë¥¢¥¯¥·¥ç¥ó¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1179          *
1180          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar" -> "/Foo/Bar.php"¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1181          *
1182          *      @access public
1183          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
1184          *      @param  bool    $fallback               ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1185          *      @return string  ¥¢¥¯¥·¥ç¥ó¥¯¥é¥¹¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1186          */
1187         function getDefaultActionPath($action_name, $fallback = true)
1188         {
1189                 $default_path = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($action_name)) . '.' . $this->getExt('php');
1190                 $action_dir = $this->getActiondir();
1191
1192                 if ($this->getClientType() == CLIENT_TYPE_SOAP) {
1193                         $r = 'SOAP/' . $default_path;
1194                 } else if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1195                         $r = 'MobileAU/' . $default_path;
1196                 } else {
1197                         $r = $default_path;
1198                 }
1199
1200                 if ($fallback && file_exists($action_dir . $r) == false && $r != $default_path) {
1201                         $this->logger->log(LOG_DEBUG, 'client_type specific file not found [%s] -> try defualt', $r);
1202                         $r = $default_path;
1203                 }
1204
1205                 $this->logger->log(LOG_DEBUG, "default action path [%s]", $r);
1206                 return $r;
1207         }
1208
1209         /**
1210          *      »ØÄꤵ¤ì¤¿Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥¯¥é¥¹Ì¾¤òÊÖ¤¹(¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤Ï¹Ô¤ï¤Ê¤¤)
1211          *
1212          *      @access public
1213          *      @param  string  $forward_name   Á«°ÜÀè¤Î̾¾Î
1214          *      @return string  view class¤Î¥¯¥é¥¹Ì¾
1215          */
1216         function getViewClassName($forward_name)
1217         {
1218                 if ($forward_name == null) {
1219                         return null;
1220                 }
1221
1222                 if (isset($this->forward[$forward_name])) {
1223                         $forward_obj = $this->forward[$forward_name];
1224                 } else {
1225                         $forward_obj = array();
1226                 }
1227
1228                 if (isset($forward_obj['view_name'])) {
1229                         $class_name = $forward_obj['view_name'];
1230                         if (class_exists($class_name)) {
1231                                 return $class_name;
1232                         }
1233                 } else {
1234                         $class_name = null;
1235                 }
1236
1237                 // view¤Î¥¤¥ó¥¯¥ë¡¼¥É
1238                 $this->_includeViewScript($forward_obj, $forward_name);
1239
1240                 if (is_null($class_name) == false && class_exists($class_name)) {
1241                         return $class_name;
1242                 } else if (is_null($class_name) == false) {
1243                         $this->logger->log(LOG_WARNING, 'stated view class is not defined [%s] -> try default', $class_name);
1244                 }
1245
1246                 $class_name = $this->getDefaultViewClass($forward_name);
1247                 if (class_exists($class_name)) {
1248                         return $class_name;
1249                 } else {
1250                         $class_name = $this->class_factory->getObjectName('view');
1251                         $this->logger->log(LOG_DEBUG, 'view class is not defined for [%s] -> use default [%s]', $forward_name, $class_name);
1252                         return $class_name;
1253                 }
1254         }
1255
1256         /**
1257          *      Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥¯¥é¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥¯¥é¥¹Ì¾¤òÊÖ¤¹
1258          *
1259          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï[¥×¥í¥¸¥§¥¯¥ÈID]_View_[Á«°Ü̾]¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1260          *
1261          *      @access public
1262          *      @param  string  $forward_name   forward̾
1263          *      @param  bool    $fallback               ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1264          *      @return string  view class¥¯¥é¥¹Ì¾
1265          */
1266         function getDefaultViewClass($forward_name, $fallback = true)
1267         {
1268                 $postfix = preg_replace('/_(.)/e', "strtoupper('\$1')", ucfirst($forward_name));
1269
1270                 $r = null;
1271                 if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1272                         $tmp = sprintf("%s_MobileAUView_%s", $this->getAppId(), $postfix);
1273                         if ($fallback == false || class_exists($tmp)) {
1274                                 $r = $tmp;
1275                         }
1276                 }
1277
1278                 if ($r == null) {
1279                         $r = sprintf("%s_View_%s", $this->getAppId(), $postfix);
1280                 }
1281                 $this->logger->log(LOG_DEBUG, "default view class [%s]", $r);
1282                 return $r;
1283         }
1284
1285         /**
1286          *      Á«°Ü̾¤ËÂбþ¤¹¤ë¥Ó¥å¡¼¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1287          *
1288          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar" -> "/Foo/Bar.php"¤È¤Ê¤ë¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1289          *
1290          *      @access public
1291          *      @param  string  $forward_name   forward̾
1292          *      @param  bool    $fallback               ¥¯¥é¥¤¥¢¥ó¥È¼ïÊ̤ˤè¤ëfallback on/off
1293          *      @return string  view class¤¬ÄêµÁ¤µ¤ì¤ë¥¹¥¯¥ê¥×¥È¤Î¥Ñ¥¹Ì¾
1294          */
1295         function getDefaultViewPath($forward_name, $fallback = true)
1296         {
1297                 $default_path = preg_replace('/_(.)/e', "'/' . strtoupper('\$1')", ucfirst($forward_name)) . '.' . $this->getExt('php');
1298                 $view_dir = $this->getViewdir();
1299
1300                 if ($this->getClientType() == CLIENT_TYPE_MOBILE_AU) {
1301                         $r = 'MobileAU/' . $r;
1302                 } else {
1303                         $r = $default_path;
1304                 }
1305
1306                 if ($fallback && file_exists($view_dir . $r) == false && $r != $default_path) {
1307                         $this->logger->log(LOG_DEBUG, 'client_type specific file not found [%s] -> try defualt', $r);
1308                         $r = $default_path;
1309                 }
1310
1311                 $this->logger->log(LOG_DEBUG, "default view path [%s]", $r);
1312                 return $r;
1313         }
1314
1315         /**
1316          *      Á«°Ü̾¤ËÂбþ¤¹¤ë¥Æ¥ó¥×¥ì¡¼¥È¥Ñ¥¹Ì¾¤¬¾Êά¤µ¤ì¤¿¾ì¹ç¤Î¥Ç¥Õ¥©¥ë¥È¥Ñ¥¹Ì¾¤òÊÖ¤¹
1317          *
1318          *      ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï"foo_bar"¤È¤¤¤¦forward̾¤¬"foo/bar" + ¥Æ¥ó¥×¥ì¡¼¥È³ÈÄ¥»Ò¤È¤Ê¤ë
1319          *      ¤Î¤Ç¹¥¤ß±þ¤¸¤Æ¥ª¡¼¥Ð¥é¥¤¥É¤¹¤ë
1320          *
1321          *      @access public
1322          *      @param  string  $forward_name   forward̾
1323          *      @return string  forward¥Ñ¥¹Ì¾
1324          */
1325         function getDefaultForwardPath($forward_name)
1326         {
1327                 return str_replace('_', '/', $forward_name) . '.' . $this->ext['tpl'];
1328         }
1329         
1330         /**
1331          *      ¥Æ¥ó¥×¥ì¡¼¥È¥Ñ¥¹Ì¾¤«¤éÁ«°Ü̾¤ò¼èÆÀ¤¹¤ë
1332          *
1333          *      getDefaultForwardPath()¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤¿¾ì¹ç¡¢¤³¤Á¤é¤â¹ç¤ï¤»¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É
1334          *      ¤¹¤ë¤³¤È¤ò¿ä¾©(ɬ¿Ü¤Ç¤Ï¤Ê¤¤)
1335          *
1336          *      @access public
1337          *      @param  string  $forward_path   ¥Æ¥ó¥×¥ì¡¼¥È¥Ñ¥¹Ì¾
1338          *      @return string  Á«°Ü̾
1339          */
1340         function forwardPathToName($forward_path)
1341         {
1342                 $forward_path = preg_replace('/^\/+/', '', $forward_path);
1343                 $forward_path = preg_replace(sprintf('/\.%s$/', $this->getExt('tpl')), '', $forward_path);
1344
1345                 return str_replace('/', '_', $forward_path);
1346         }
1347
1348         /**
1349          *      Á«°Ü̾¤«¤é¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹Ì¾¤ò¼èÆÀ¤¹¤ë
1350          *
1351          *      @access private
1352          *      @param  string  $forward_name   forward̾
1353          *      @return string  ¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹Ì¾
1354          */
1355         function _getForwardPath($forward_name)
1356         {
1357                 $forward_obj = null;
1358
1359                 if (isset($this->forward[$forward_name]) == false) {
1360                         // try default
1361                         $this->forward[$forward_name] = array();
1362                 }
1363                 $forward_obj =& $this->forward[$forward_name];
1364                 if (isset($forward_obj['forward_path']) == false) {
1365                         // ¾ÊάÃÍÊäÀµ
1366                         $forward_obj['forward_path'] = $this->getDefaultForwardPath($forward_name);
1367                 }
1368
1369                 return $forward_obj['forward_path'];
1370         }
1371
1372         /**
1373          *      ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¼èÆÀ¤¹¤ë(¸½ºß¤Ïsmarty¤Î¤ßÂбþ)
1374          *
1375          *      @access public
1376          *      @return object  Smarty  ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¥ª¥Ö¥¸¥§¥¯¥È
1377          */
1378         function &getTemplateEngine()
1379         {
1380                 $smarty =& new Smarty();
1381                 $smarty->template_dir = $this->getTemplatedir();
1382                 $smarty->compile_dir = $this->getDirectory('template_c') . '/tpl_' . md5($smarty->template_dir);
1383                 if (@is_dir($smarty->compile_dir) == false) {
1384                         mkdir($smarty->compile_dir, 0755);
1385                 }
1386                 $smarty->plugins_dir = $this->getDirectory('plugins');
1387
1388                 // default modifiers
1389                 $smarty->register_modifier('number_format', 'smarty_modifier_number_format');
1390                 $smarty->register_modifier('strftime', 'smarty_modifier_strftime');
1391                 $smarty->register_modifier('count', 'smarty_modifier_count');
1392                 $smarty->register_modifier('join', 'smarty_modifier_join');
1393                 $smarty->register_modifier('filter', 'smarty_modifier_filter');
1394                 $smarty->register_modifier('unique', 'smarty_modifier_unique');
1395                 $smarty->register_modifier('wordwrap_i18n', 'smarty_modifier_wordwrap_i18n');
1396                 $smarty->register_modifier('truncate_i18n', 'smarty_modifier_truncate_i18n');
1397                 $smarty->register_modifier('i18n', 'smarty_modifier_i18n');
1398                 $smarty->register_modifier('checkbox', 'smarty_modifier_checkbox');
1399                 $smarty->register_modifier('select', 'smarty_modifier_select');
1400                 $smarty->register_modifier('form_value', 'smarty_modifier_form_value');
1401
1402                 // user defined modifiers
1403                 foreach ($this->smarty_modifier_plugin as $modifier) {
1404                         $name = str_replace('smarty_modifier_', '', $modifier);
1405                         $smarty->register_modifier($name, $modifier);
1406                 }
1407
1408                 // default functions
1409                 $smarty->register_function('is_error', 'smarty_function_is_error');
1410                 $smarty->register_function('message', 'smarty_function_message');
1411                 $smarty->register_function('uniqid', 'smarty_function_uniqid');
1412                 $smarty->register_function('select', 'smarty_function_select');
1413                 $smarty->register_function('checkbox_list', 'smarty_function_checkbox_list');
1414
1415                 // user defined functions
1416                 foreach ($this->smarty_function_plugin as $function) {
1417                         $name = str_replace('smarty_function_', '', $function);
1418                         $smarty->register_function($name, $function);
1419                 }
1420
1421                 // user defined prefilters
1422                 foreach ($this->smarty_prefilter_plugin as $prefilter) {
1423                         $smarty->register_prefilter($prefilter);
1424                 }
1425
1426                 // user defined postfilters
1427                 foreach ($this->smarty_postfilter_plugin as $postfilter) {
1428                         $smarty->register_postfilter($postfilter);
1429                 }
1430
1431                 // user defined outputfilters
1432                 foreach ($this->smarty_outputfilter_plugin as $outputfilter) {
1433                         $smarty->register_outputfilter($outputfilter);
1434                 }
1435
1436                 $this->_setDefaultTemplateEngine($smarty);
1437
1438                 return $smarty;
1439         }
1440
1441         /**
1442          *  ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¤Î¥Ç¥Õ¥©¥ë¥È¾õÂÖ¤òÀßÄꤹ¤ë
1443          *
1444          *  @access protected
1445          *  @param  object  Smarty  $smarty ¥Æ¥ó¥×¥ì¡¼¥È¥¨¥ó¥¸¥ó¥ª¥Ö¥¸¥§¥¯¥È
1446          */
1447         function _setDefaultTemplateEngine(&$smarty)
1448         {
1449         }
1450
1451         /**
1452          *      »ÈÍѸÀ¸ì¤òÀßÄꤹ¤ë
1453          *
1454          *      ¾­Íè¤Ø¤Î³ÈÄ¥¤Î¤¿¤á¤Î¤ß¤Ë¸ºß¤·¤Æ¤¤¤Þ¤¹¡£¸½ºß¤ÏÆä˥ª¡¼¥Ð¡¼¥é¥¤¥É¤ÎɬÍפϤ¢¤ê¤Þ¤»¤ó¡£
1455          *
1456          *      @access protected
1457          *      @param  string  $language                       ¸À¸ìÄêµÁ(LANG_JA, LANG_EN...)
1458          *      @param  string  $system_encoding        ¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
1459          *      @param  string  $client_encoding        ¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
1460          */
1461         function _setLanguage($language, $system_encoding = null, $client_encoding = null)
1462         {
1463                 $this->language = $language;
1464                 $this->system_encoding = $system_encoding;
1465                 $this->client_encoding = $client_encoding;
1466
1467                 $i18n =& $this->getI18N();
1468                 $i18n->setLanguage($language, $system_encoding, $client_encoding);
1469         }
1470
1471         /**
1472          *      ¥Ç¥Õ¥©¥ë¥È¾õÂ֤ǤλÈÍѸÀ¸ì¤ò¼èÆÀ¤¹¤ë
1473          *
1474          *      @access protected
1475          *      @return array   »ÈÍѸÀ¸ì,¥·¥¹¥Æ¥à¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾,¥¯¥é¥¤¥¢¥ó¥È¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°Ì¾
1476          */
1477         function _getDefaultLanguage()
1478         {
1479                 return array(LANG_JA, null, null);
1480         }
1481
1482         /**
1483          *      ¥Ç¥Õ¥©¥ë¥È¾õÂ֤ǤΥ¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×¤ò¼èÆÀ¤¹¤ë
1484          *
1485          *      @access protected
1486          *      @return int             ¥¯¥é¥¤¥¢¥ó¥È¥¿¥¤¥×ÄêµÁ(CLIENT_TYPE_WWW...)
1487          */
1488         function _getDefaultClientType()
1489         {
1490                 if (is_null($GLOBALS['_Ethna_client_type']) == false) {
1491                         return $GLOBALS['_Ethna_client_type'];
1492                 }
1493                 return CLIENT_TYPE_WWW;
1494         }
1495
1496         /**
1497          *      ¥Þ¥Í¡¼¥¸¥ã¥¯¥é¥¹Ì¾¤ò¼èÆÀ¤¹¤ë
1498          *
1499          *      @access public
1500          *      @param  string  $name   ¥Þ¥Í¡¼¥¸¥ã̾
1501          *      @return string  ¥Þ¥Í¡¼¥¸¥ã¥¯¥é¥¹Ì¾
1502          */
1503         function getManagerClassName($name)
1504         {
1505                 return sprintf('%s_%sManager', $this->getAppId(), ucfirst($name));
1506         }
1507
1508         /**
1509          *      ¥¢¥¯¥·¥ç¥ó¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1510          *
1511          *      ¤¿¤À¤·¡¢¥¤¥ó¥¯¥ë¡¼¥É¤·¤¿¥Õ¥¡¥¤¥ë¤Ë¥¯¥é¥¹¤¬Àµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÏÊݾڤ·¤Ê¤¤
1512          *
1513          *      @access private
1514          *      @param  array   $action_obj             ¥¢¥¯¥·¥ç¥óÄêµÁ
1515          *      @param  string  $action_name    ¥¢¥¯¥·¥ç¥ó̾
1516          */
1517         function _includeActionScript($action_obj, $action_name)
1518         {
1519                 $class_path = $form_path = null;
1520
1521                 $action_dir = $this->getActiondir();
1522
1523                 // class_path°À­¥Á¥§¥Ã¥¯
1524                 if (isset($action_obj['class_path'])) {
1525                         // ¥Õ¥ë¥Ñ¥¹»ØÄꥵ¥Ý¡¼¥È
1526                         $tmp_path = $action_obj['class_path'];
1527                         if (Ethna_Util::isAbsolute($tmp_path) == false) {
1528                                 $tmp_path = $action_dir . $tmp_path;
1529                         }
1530
1531                         if (file_exists($tmp_path) == false) {
1532                                 $this->logger->log(LOG_WARNING, 'class_path file not found [%s] -> try default', $tmp_path);
1533                         } else {
1534                                 include_once($tmp_path);
1535                                 $class_path = $tmp_path;
1536                         }
1537                 }
1538
1539                 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1540                 if (is_null($class_path)) {
1541                         $class_path = $this->getDefaultActionPath($action_name);
1542                         if (file_exists($action_dir . $class_path)) {
1543                                 include_once($action_dir . $class_path);
1544                         } else {
1545                                 $this->logger->log(LOG_DEBUG, 'default action file not found [%s] -> try all files', $class_path);
1546                                 $class_path = null;
1547                         }
1548                 }
1549                 
1550                 // Á´¥Õ¥¡¥¤¥ë¥¤¥ó¥¯¥ë¡¼¥É
1551                 if (is_null($class_path)) {
1552                         $this->_includeDirectory($this->getActiondir());
1553                         return;
1554                 }
1555
1556                 // form_path°À­¥Á¥§¥Ã¥¯
1557                 if (isset($action_obj['form_path'])) {
1558                         // ¥Õ¥ë¥Ñ¥¹»ØÄꥵ¥Ý¡¼¥È
1559                         $tmp_path = $action_obj['class_path'];
1560                         if (Ethna_Util::isAbsolute($tmp_path) == false) {
1561                                 $tmp_path = $action_dir . $tmp_path;
1562                         }
1563
1564                         if ($tmp_path == $class_path) {
1565                                 return;
1566                         }
1567                         if (file_exists($tmp_path) == false) {
1568                                 $this->logger->log(LOG_WARNING, 'form_path file not found [%s] -> try default', $tmp_path);
1569                         } else {
1570                                 include_once($tmp_path);
1571                                 $form_path = $tmp_path;
1572                         }
1573                 }
1574
1575                 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1576                 if (is_null($form_path)) {
1577                         $form_path = $this->getDefaultFormPath($action_name);
1578                         if ($form_path == $class_path) {
1579                                 return;
1580                         }
1581                         if (file_exists($action_dir . $form_path)) {
1582                                 include_once($action_dir . $form_path);
1583                         } else {
1584                                 $this->logger->log(LOG_DEBUG, 'default form file not found [%s] -> maybe falling back to default form class', $form_path);
1585                         }
1586                 }
1587         }
1588
1589         /**
1590          *      ¥Ó¥å¡¼¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1591          *
1592          *      ¤¿¤À¤·¡¢¥¤¥ó¥¯¥ë¡¼¥É¤·¤¿¥Õ¥¡¥¤¥ë¤Ë¥¯¥é¥¹¤¬Àµ¤·¤¯ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤ÏÊݾڤ·¤Ê¤¤
1593          *
1594          *      @access private
1595          *      @param  array   $forward_obj    Á«°ÜÄêµÁ
1596          *      @param  string  $forward_name   Á«°Ü̾
1597          */
1598         function _includeViewScript($forward_obj, $forward_name)
1599         {
1600                 $view_dir = $this->getViewdir();
1601
1602                 // view_path°À­¥Á¥§¥Ã¥¯
1603                 if (isset($forward_obj['view_path'])) {
1604                         // ¥Õ¥ë¥Ñ¥¹»ØÄꥵ¥Ý¡¼¥È
1605                         $tmp_path = $forward_obj['view_path'];
1606                         if (Ethna_Util::isAbsolute($tmp_path) == false) {
1607                                 $tmp_path = $view_dir . $tmp_path;
1608                         }
1609
1610                         if (file_exists($tmp_path) == false) {
1611                                 $this->logger->log(LOG_WARNING, 'view_path file not found [%s] -> try default', $tmp_path);
1612                         } else {
1613                                 include_once($tmp_path);
1614                                 return;
1615                         }
1616                 }
1617
1618                 // ¥Ç¥Õ¥©¥ë¥È¥Á¥§¥Ã¥¯
1619                 $view_path = $this->getDefaultViewPath($forward_name);
1620                 if (file_exists($view_dir . $view_path)) {
1621                         include_once($view_dir . $view_path);
1622                         return;
1623                 } else {
1624                         $this->logger->log(LOG_DEBUG, 'default view file not found [%s]', $view_path);
1625                         $view_path = null;
1626                 }
1627         }
1628
1629         /**
1630          *      ¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤ÎÁ´¤Æ¤Î¥¹¥¯¥ê¥×¥È¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
1631          *
1632          *      @access private
1633          */
1634         function _includeDirectory($dir)
1635         {
1636                 $ext = "." . $this->ext['php'];
1637                 $ext_len = strlen($ext);
1638
1639                 if (is_dir($dir) == false) {
1640                         return;
1641                 }
1642
1643                 $dh = opendir($dir);
1644                 if ($dh) {
1645                         while (($file = readdir($dh)) !== false) {
1646                                 if ($file != '.' && $file != '..' && is_dir("$dir/$file")) {
1647                                         $this->_includeDirectory("$dir/$file");
1648                                 }
1649                                 if (substr($file, -$ext_len, $ext_len) != $ext) {
1650                                         continue;
1651                                 }
1652                                 include_once("$dir/$file");
1653                         }
1654                 }
1655                 closedir($dh);
1656         }
1657
1658         /**
1659          *      ÀßÄê¥Õ¥¡¥¤¥ë¤ÎDSNÄêµÁ¤«¤é»ÈÍѤ¹¤ë¥Ç¡¼¥¿¤òºÆ¹½ÃÛ¤¹¤ë(¥¹¥ì¡¼¥Ö¥¢¥¯¥»¥¹Ê¬´ôÅù)
1660          *
1661          *      DSN¤ÎÄêµÁÊýË¡(¥Ç¥Õ¥©¥ë¥È:ÀßÄê¥Õ¥¡¥¤¥ë)¤òÊѤ¨¤¿¤¤¾ì¹ç¤Ï¤³¤³¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1662          *
1663          *      @access protected
1664          *      @return array   DSNÄêµÁ
1665          */
1666         function _prepareDSN()
1667         {
1668                 $r = array();
1669
1670                 foreach ($this->db as $key => $value) {
1671                         $config_key = "dsn";
1672                         if ($key != "") {
1673                                 $config_key .= "_$key";
1674                         }
1675                         $dsn = $this->config->get($config_key);
1676                         if (is_array($dsn)) {
1677                                 // ¼ïÊÌ1¤Ä¤Ë¤Ä¤­Ê£¿ôDSN¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¥¢¥¯¥»¥¹Ê¬´ô
1678                                 $dsn = $this->_selectDSN($key, $dsn);
1679                         }
1680                         $r[$key] = $dsn;
1681                 }
1682                 return $r;
1683         }
1684
1685         /**
1686          *      DSN¤Î¥¢¥¯¥»¥¹Ê¬´ô¤ò¹Ô¤¦
1687          *      
1688          *      ¥¹¥ì¡¼¥Ö¥µ¡¼¥Ð¤Ø¤Î¿¶Ê¬¤±½èÍý(¥Ç¥Õ¥©¥ë¥È:¥é¥ó¥À¥à)¤òÊѹ¹¤·¤¿¤¤¾ì¹ç¤Ï¤³¤Î¥á¥½¥Ã¥É¤ò¥ª¡¼¥Ð¡¼¥é¥¤¥É¤¹¤ë
1689          *
1690          *      @access protected
1691          *      @param  string  $type           DB¼ïÊÌ
1692          *      @param  array   $dsn_list       DSN°ìÍ÷
1693          *      @return string  ÁªÂò¤µ¤ì¤¿DSN
1694          */
1695         function _selectDSN($type, $dsn_list)
1696         {
1697                 // ¥Ç¥Õ¥©¥ë¥È:¥é¥ó¥À¥à
1698                 list($usec, $sec) = explode(' ', microtime());
1699                 mt_srand($sec + ((float) $usec * 100000));
1700                 $n = mt_rand(0, count($dsn_list)-1);
1701                 
1702                 return $dsn_list[$n];
1703         }
1704
1705         /**
1706          *      Ethna¥Þ¥Í¡¼¥¸¥ã¤òÀßÄꤹ¤ë
1707          *
1708          *      ÉÔÍפʾì¹ç¤Ï¶õ¤Î¥á¥½¥Ã¥É¤È¤·¤Æ¥ª¡¼¥Ð¡¼¥é¥¤¥É¤·¤Æ¤â¤è¤¤
1709          *
1710          *      @access protected
1711          */
1712         function _activateEthnaManager()
1713         {
1714                 if ($this->config->get('debug') == false) {
1715                         return;
1716                 }
1717
1718                 include_once(ETHNA_BASE . '/class/Ethna_InfoManager.php');
1719
1720                 // actionÀßÄê
1721                 $this->action['__ethna_info__'] = array(
1722                         'form_name' =>  'Ethna_Form_Info',
1723                         'form_path' =>  sprintf('%s/class/Action/Ethna_Action_Info.php', ETHNA_BASE),
1724                         'class_name' => 'Ethna_Action_Info',
1725                         'class_path' => sprintf('%s/class/Action/Ethna_Action_Info.php', ETHNA_BASE),
1726                 );
1727
1728                 // forwardÀßÄê
1729                 $this->forward['__ethna_info__'] = array(
1730                         'forward_path'  => sprintf('%s/tpl/info.tpl', ETHNA_BASE),
1731                         'view_name'             => 'Ethna_View_Info',
1732                         'view_path'             => sprintf('%s/class/View/Ethna_View_Info.php', ETHNA_BASE),
1733                 );
1734         }
1735 }
1736 // }}}
1737 ?>