Example #1
0
 /**
  *  Ethna_ActionFormクラスのコンストラクタ
  *
  */
 public function __construct(ContainerInterface $container)
 {
     $this->container = $container;
     $this->action_error = $container->getActionError();
     $this->ae = $this->action_error;
     $this->action_error->action_form = $this;
     $this->i18n = $container->getI18N();
     $this->logger = $container->getLogger();
     $this->plugin = $container->getPlugin();
     if (isset($_SERVER['REQUEST_METHOD']) == false) {
         return;
     }
     // フォーム値テンプレートの更新
     $this->form_template = $this->_setFormTemplate($this->form_template);
     // フォーム値定義の設定
     $this->_setFormDef();
     // 省略値補正
     foreach ($this->form as $name => $value) {
         foreach ($this->def as $k) {
             if (isset($value[$k]) == false) {
                 $this->form[$name][$k] = null;
             }
         }
     }
 }
Example #2
0
 /**
  *
  */
 public function __construct(ContainerInterface $container)
 {
     $this->container = $container;
     $this->config = $container->getConfig();
     $this->i18n = $container->getI18N();
     $this->plugin = $container->getPlugin();
     $this->logger = $container->getLogger();
 }
Example #3
0
 /**
  *  コンストラクタ
  *
  *  @access public
  */
 public function __construct(Ethna_ContainerInterface $container)
 {
     $this->config = $container->getConfig();
     // load config
     $this->_loadConfig();
     if (isset($this->opt['namespace'])) {
         $this->namespace = $this->opt['namespace'];
     }
 }
Example #4
0
 /**
  *  Ethna_Sessionクラスのコンストラクタ
  *
  *  @access public
  */
 public function __construct(ContainerInterface $container, string $sessionName)
 {
     $this->logger = $container->getLogger();
     $config = $container->getConfig()->get('session');
     if ($config) {
         $this->config = array_merge($this->config, $config);
     }
     $this->session_save_dir = $this->config['path'];
     if (($dir = $container->getDirectory($this->config['path'])) !== null) {
         $this->session_save_dir = $dir;
     }
     $this->session_name = $sessionName;
     // set session handler
     ini_set('session.save_handler', $this->config['handler']);
     session_save_path($this->session_save_dir);
     session_name($this->session_name);
     session_cache_limiter($this->config['cache_limiter']);
     session_cache_expire($this->config['cache_expire']);
     $this->session_start = false;
 }
Example #5
0
 /**
  *  Ethna_ActionClassのコンストラクタ
  *
  */
 public function __construct(ContainerInterface $container, $action_form, $viewResolver)
 {
     $this->container = $container;
     $this->config = $container->getConfig();
     $this->i18n = $container->getI18N();
     $this->action_error = $container->getActionError();
     $this->ae = $this->action_error;
     $this->action_form = $action_form;
     $this->af = $this->action_form;
     $this->session = $container->getSession();
     $this->plugin = $container->getPlugin();
     $this->logger = $container->getLogger();
     $this->viewResolver = $viewResolver;
 }
Example #6
0
 /**
  *  アラートメールを送信する
  *
  *  @access protected
  *  @param  string  $message    ログメッセージ
  *  @return int     0:正常終了
  *  @deprecated
  */
 protected function _alert($message)
 {
     restore_error_handler();
     // ヘッダ
     $header = "Mime-Version: 1.0\n";
     $header .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
     $header .= "X-Alert: " . $this->container->getAppId();
     $subject = sprintf("[%s] alert (%s%s)\n", $this->container->getAppId(), substr($message, 0, 12), strlen($message) > 12 ? "..." : "");
     // 本文
     $mail = sprintf("--- [log message] ---\n%s\n\n", $message);
     if (function_exists("debug_backtrace")) {
         $bt = debug_backtrace();
         $mail .= sprintf("--- [backtrace] ---\n%s\n", Ethna_Util::FormatBacktrace($bt));
     }
     foreach ($this->alert_mailaddress as $mailaddress) {
         mail($mailaddress, $subject, mb_convert_encoding($mail, "ISO-2022-JP"), $header);
     }
     set_error_handler("ethna_error_handler");
     return 0;
 }
Example #7
0
 /**
  *  プラグインのクラス名、ディレクトリ、ファイル名を決定
  *
  *  @access public
  *  @param  string  $type   プラグインの種類
  *  @param  string  $name   プラグインの名前 (nullのときは親クラス)
  *  @param  string  $appid  アプリケーションID (廃止予定)
  *  @return array   プラグインのクラス名、ディレクトリ、ファイル名の配列
  */
 public function getPluginNaming($type, $name, $appid = 'Ethna')
 {
     $ext = $this->container->getExt('php');
     $plugin_class_name = array($appid, 'Plugin', $type);
     if ($appid == 'Ethna') {
         $baseDir = ETHNA_BASE . "/src/Plugin";
     } else {
         $baseDir = $this->container->getDirectory('plugin');
     }
     if ($name !== null) {
         $plugin_class_name[] = $name;
         $dir = $baseDir . "/{$type}";
         $basename = "{$name}.{$ext}";
     } else {
         //親クラス
         $dir = $baseDir;
         $basename = "{$type}.{$ext}";
     }
     $class = implode('_', $plugin_class_name);
     return array($class, $dir, $basename);
 }
Example #8
0
 /**
  *  Csrfのコンストラクタ
  *
  *  @access public
  */
 public function __construct(Ethna_ContainerInterface $container)
 {
     $this->config = $container->getConfig();
     $this->logger = $container->getLogger();
 }
Example #9
0
 /**
  *  メールを送信する
  *
  *  $attach の指定方法:
  *  - 既存のファイルを添付するとき
  *  <code>
  *  array('filename' => '/tmp/hoge.xls', 'content-type' => 'application/vnd.ms-excel')
  *  </code>
  *  - 文字列に名前を付けて添付するとき
  *  <code>
  *  array('name' => 'foo.txt', 'content' => 'this is foo.')
  *  </code>
  *  'content-type' 省略時は 'application/octet-stream' となる。
  *  複数添付するときは上の配列を添字0から始まるふつうの配列に入れる。
  *
  *  @access public
  *  @param  string  $to         メール送信先アドレス (nullのときは送信せずに内容を return する)
  *  @param  string  $template   メールテンプレート名 or タイプ
  *  @param  array   $macro      テンプレートマクロ or $templateがMAILSENDER_TYPE_DIRECTのときはメール送信内容)
  *  @param  array   $attach     添付ファイル
  */
 function send($to, $template, $macro, $attach = null)
 {
     // メール内容を作成
     if ($template === MAILSENDER_TYPE_DIRECT) {
         $mail = $macro;
     } else {
         $renderer = $this->container->getRenderer();
         // 基本情報設定
         $env_datetime = _et('%Y/%m/%d %H:%M:%S');
         $renderer->setProp("env_datetime", strftime($env_datetime));
         $renderer->setProp("env_useragent", $_SERVER["HTTP_USER_AGENT"]);
         $renderer->setProp("env_remoteaddr", $_SERVER["REMOTE_ADDR"]);
         // デフォルトマクロ設定
         $macro = $this->_setDefaultMacro($macro);
         // ユーザ定義情報設定
         if (is_array($macro)) {
             foreach ($macro as $key => $value) {
                 $renderer->setProp($key, $value);
             }
         }
         if (isset($this->def[$template])) {
             $template = $this->def[$template];
         }
         $mail = $renderer->perform(sprintf('%s/%s', $this->mail_dir, $template), true);
         if (Ethna::isError($mail)) {
             return $mail;
         }
     }
     if ($to === null) {
         return $mail;
     }
     // メール内容をヘッダと本文に分離
     $mail = str_replace("\r\n", "\n", $mail);
     list($header, $body) = $this->_parse($mail);
     // 添付ファイル (multipart)
     if ($attach !== null) {
         $attach = isset($attach[0]) ? $attach : array($attach);
         $boundary = Ethna_Util::getRandom();
         $body = "This is a multi-part message in MIME format.\n\n" . "--{$boundary}\n" . "Content-Type: text/plain; charset=utf-8\n" . "Content-Transfer-Encoding: 8bit\n\n" . "{$body}\n";
         foreach ($attach as $part) {
             if (isset($part['content']) === false && isset($part['filename']) && is_readable($part['filename'])) {
                 $part['content'] = file_get_contents($part['filename']);
                 $part['filename'] = basename($part['filename']);
             }
             if (isset($part['content']) === false) {
                 continue;
             }
             if (isset($part['content-type']) === false) {
                 $part['content-type'] = 'application/octet-stream';
             }
             if (isset($part['name']) === false) {
                 $part['name'] = $part['filename'];
             }
             if (isset($part['filename']) === false) {
                 $part['filename'] = $part['name'];
             }
             $part['name'] = preg_replace_callback('/([^\\x00-\\x7f]+)/', function ($matches) {
                 return Ethna_Util::encode_MIME($matches[1]);
             }, $part['name']);
             // XXX: rfc2231
             $part['filename'] = preg_replace_callback('/([^\\x00-\\x7f]+)/', function ($matches) {
                 return Ethna_Util::encode_MIME($matches[1]);
             }, $part['filename']);
             $body .= "--{$boundary}\n" . "Content-Type: " . $part['content-type'] . ";\n" . "\tname=\"" . $part['name'] . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . "\tfilename=\"" . $part['filename'] . "\"\n\n";
             $body .= chunk_split(base64_encode($part['content']));
         }
         $body .= "--{$boundary}--";
     }
     // ヘッダ
     if (isset($header['mime-version']) === false) {
         $header['mime-version'] = array('Mime-Version', '1.0');
     }
     if (isset($header['subject']) === false) {
         $header['subject'] = array('Subject', 'no subject in original');
     }
     if (isset($header['content-type']) === false) {
         $header['content-type'] = array('Content-Type', $attach === null ? 'text/plain; charset=utf-8' : "multipart/mixed; \n\tboundary=\"{$boundary}\"");
     }
     if (isset($header['content-transfer-encoding']) === false) {
         $header['Content-Transfer-Encoding'] = ['Content-Transfer-Encoding', '8bit'];
     }
     $header_line = "";
     foreach ($header as $key => $value) {
         if ($key == 'subject') {
             // should be added by mail()
             continue;
         }
         if ($header_line != "") {
             $header_line .= "\n";
         }
         $header_line .= $value[0] . ": " . $value[1];
     }
     // 改行コードを CRLF に
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $body = str_replace("\n", "\r\n", $body);
     }
     $wa_config = 'mail_func_workaround';
     if ($this->config->get($wa_config) == false && isset($this->options[$wa_config]) == false) {
         $header_line = str_replace("\n", "\r\n", $header_line);
     }
     // 送信
     foreach (to_array($to) as $rcpt) {
         if (is_string($this->option)) {
             mail($rcpt, $header['subject'][1], $body, $header_line, $this->option);
         } else {
             mail($rcpt, $header['subject'][1], $body, $header_line);
         }
     }
 }