OSDN Git Service

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