示例#1
0
 function execute($params)
 {
     $post = Vizualizer::request();
     if (!empty($post[$params->get("key")])) {
         if (Vizualizer::now()->getTime() < strtotime($post[$params->get("key")])) {
             throw new Vizualizer_Exception_Invalid($params->get("key"), $params->get("value") . $params->get("suffix", "は未来の日付です。"));
         }
     }
 }
示例#2
0
/**
 * Smarty {now} function plugin
 *
 * Type: function<br>
 * Name: uniqid<br>
 * Purpose: call vizualizer current time control function.<br>
 *
 * @author Naohisa Minagawa <minagawa at web-life dot co dot jp>
 * @param array $params parameters
 * @param object $smarty Smarty object
 * @param object $template template object
 * @return string null
 */
function smarty_function_now($params, $template)
{
    $time = Vizualizer::now();
    if (!empty($params["value"])) {
        $time = $time->strToTime($params["value"]);
    }
    if (!empty($params["format"])) {
        return $time->date($params["format"]);
    }
    return $time->date("Y-m-d H:i:s");
}
示例#3
0
 function execute($params)
 {
     if ($params->check("result")) {
         $post = Vizualizer::request();
         if ($params->check("parent")) {
             $parent = $post[$params->get("parent")];
             if (empty($parent[$params->get("result")])) {
                 $parent[$params->get("result")] = Vizualizer::now()->date($params->get("format", "Y-m-d"));
                 $post->set($params->get("parent"), $parent);
             }
         } else {
             if (empty($post[$params->get("result")])) {
                 $post->set($params->get("result"), Vizualizer::now()->date($params->get("format", "Y-m-d")));
             }
         }
     }
 }
 function execute($params)
 {
     $post = Vizualizer::request();
     $errors = array();
     $result = "";
     if ($params->check("year") && isset($post[$params->get("year")]) && is_numeric($post[$params->get("year")]) && $params->check("month") && isset($post[$params->get("month")]) && is_numeric($post[$params->get("month")]) && $params->check("day") && isset($post[$params->get("day")]) && is_numeric($post[$params->get("day")])) {
         $result .= sprintf("%04d", $post[$params->get("year")]);
         $result .= "-";
         $result .= sprintf("%02d", $post[$params->get("month")]);
         $result .= "-";
         $result .= sprintf("%02d", $post[$params->get("day")]);
         if (Vizualizer::now()->strToTime($result)->date("Y-m-d") != $result) {
             throw new Vizualizer_Exception_Invalid($params->get("result"), $params->get("result_name") . $params->get("suffix", "は日付の指定が正しくありません。"));
         }
         if ($params->check("hour") && isset($post[$params->get("hour")]) && is_numeric($post[$params->get("hour")]) && $params->check("minute") && isset($post[$params->get("minute")]) && is_numeric($post[$params->get("minute")])) {
             if (!empty($post[$params->get("result")])) {
                 $post[$params->get("result")] .= " ";
             }
             $result .= sprintf("%02d", $post[$params->get("hour")]);
             $result .= ":";
             $result .= sprintf("%02d", $post[$params->get("minute")]);
             if (Vizualizer::now()->strToTime($result)->date("Y-m-d H:i") != $result) {
                 throw new Vizualizer_Exception_Invalid($params->get("result"), $params->get("result_name") . $params->get("suffix", "は日付の指定が正しくありません。"));
             }
             if ($params->check("second") && isset($post[$params->get("second")]) && is_numeric($post[$params->get("second")])) {
                 $result .= ":";
                 $result .= sprintf("%02d", $post[$params->get("second")]);
                 if (Vizualizer::now()->strToTime($result)->date("Y-m-d H:i:s") != $result) {
                     throw new Vizualizer_Exception_Invalid($params->get("result"), $params->get("result_name") . $params->get("suffix", "は日付の指定が正しくありません。"));
                 }
             }
         } elseif ($params->check("hourminute") && isset($post[$params->get("hourminute")])) {
             if (!empty($result)) {
                 $result .= " ";
             }
             $result .= $post[$params->get("hourminute")];
             if (Vizualizer::now()->strToTime($result)->date("Y-m-d H:i") != $result) {
                 throw new Vizualizer_Exception_Invalid($params->get("result"), $params->get("result_name") . $params->get("suffix", "は日付の指定が正しくありません。"));
             }
         }
         $post->set($params->get("result"), $result);
     }
 }
示例#5
0
 /**
  * キャッシュを利用するためのメソッド
  */
 protected static function cacheData($key, $value = null)
 {
     if (!self::$cached || self::$cachedTime != Vizualizer::now()->date("YmdHis")) {
         // キャッシュデータが無いか、キャッシュ時間が更新されている場合は初期化
         self::$cachedTime = Vizualizer::now()->date("YmdHis");
         self::$cached = array();
     }
     if ($value !== null) {
         // 値が設定されている場合にはキーに対応する値に設定
         self::$cached[$key] = $value;
     }
     // キャッシュが存在する場合には値を返し、存在しない場合にはnullを返す。
     if (array_key_exists($key, self::$cached)) {
         return self::$cached[$key];
     }
     return null;
 }
示例#6
0
 protected function executeImpl($params, $type, $name, $result, $defaultSortKey = "create_time")
 {
     if (!$params->check("search") || isset($_POST[$params->get("search")])) {
         $loader = new Vizualizer_Plugin($type);
         // カテゴリが選択された場合、カテゴリの商品IDのリストを使う
         $conditions = array();
         $post = Vizualizer::request();
         if (is_array($post["search"])) {
             foreach ($post["search"] as $key => $value) {
                 if (!$this->isEmpty($value)) {
                     $conditions[$key] = $value;
                 }
             }
         }
         // 並べ替え順序が指定されている場合に適用
         $sortOrder = "";
         $sortReverse = false;
         if ($params->check("sort_key")) {
             $sortOrder = $post[$params->get("sort_key")];
             if ($this->isEmpty($sortOrder)) {
                 $sortOrder = $defaultSortKey;
                 $sortReverse = true;
             } elseif (strpos($sortOrder, "rev@") === 0) {
                 list($dummy, $sortOrder) = explode("@", $sortOrder);
                 $sortReverse = true;
             }
         }
         $model = $loader->LoadModel($name);
         // 顧客データを検索する。
         if ($this->groupBy) {
             $model->setGroupBy($this->groupBy);
         }
         if ($params->get("force_operator", "0") == "1") {
             $model->setIgnoreOperator(true);
         }
         $result = $model->findAllBy($conditions, $sortOrder, $sortReverse);
         if ($params->check("columns")) {
             $columns = explode(",", $params->get("columns"));
         } else {
             $columns = $model->columns();
         }
         if ($params->check("titles")) {
             $titles = explode(",", $params->get("titles"));
         } else {
             $titles = $columns;
         }
         // ヘッダを送信
         header("Content-Type: application/csv");
         header("Content-Disposition: attachment; filename=\"" . $params->get("prefix", "csvfile") . Vizualizer::now()->date("YmdHis") . ".csv\"");
         ob_end_clean();
         ob_start();
         // CSVヘッダを出力
         $out = fopen("php://output", "w");
         fputcsv($out, $titles);
         foreach ($result as $data) {
             // データが0件以上の場合は繰り返し
             $output = array();
             $data = $this->filterData($data);
             foreach ($columns as $index => $column) {
                 $output[] = $data->{$column};
             }
             fputcsv($out, $output);
         }
         fclose($out);
         echo mb_convert_encoding(ob_get_clean(), "Shift_JIS", "UTF-8");
         $this->postprocess();
         exit;
     }
 }
示例#7
0
 /**
  * デフォルト実行のメソッドになります。
  * このメソッド以外がモジュールとして呼ばれることはありません。
  *
  * @param array $params モジュールの受け取るパラメータ
  */
 public function execute($params)
 {
     // 出力バッファをリセットする。
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     Vizualizer_Logger::$logFilePrefix = "batch_";
     Vizualizer_Logger::$logOutputStandard = true;
     $this->info("Batch " . $this->getName() . " Start.");
     if ($this->getDaemonName() != "") {
         if (count($params) > 3 && $params[3] == "stop") {
             if (($fp = fopen($this->getDaemonName() . ".unlock", "w+")) !== FALSE) {
                 fclose($fp);
             }
         } elseif (($fp = fopen($this->getDaemonName() . ".lock", "a+")) !== FALSE) {
             if (!flock($fp, LOCK_EX | LOCK_NB)) {
                 list($time, $pid) = explode(",", trim(file_get_contents($this->getDaemonName() . ".lock")));
                 // 12時間以上起動し続けている場合は再起動を実施
                 if ($time + 12 * 3600 < time()) {
                     system("kill -KILL " . $pid);
                 }
                 $this->info("Batch " . $this->getName() . " was already running.");
                 die("プログラムは既に実行中です。");
             }
             // デーモンの起動時刻とプロセスIDをロックファイルに記述
             ftruncate($fp, 0);
             fwrite($fp, time() . "," . getmypid());
             if ($this->isUnlocked()) {
                 // 実行前にunlockファイルがある場合は予め削除する。
                 unlink($this->getDaemonName() . ".unlock");
             }
             while (true) {
                 Vizualizer::now()->reset();
                 $this->info("==== START " . $this->getName() . " ROUTINE ======");
                 $this->executeImpl($params);
                 $this->info("==== END " . $this->getName() . " ROUTINE ======");
                 if (file_exists($this->getDaemonName() . ".unlock")) {
                     // unlockファイルがある場合はループを終了
                     unlink($this->getDaemonName() . ".unlock");
                     break;
                 }
                 // 一周回ったら所定秒数ウェイト
                 if ($this->getDaemonInterval() > 10) {
                     sleep($this->getDaemonInterval());
                 } else {
                     sleep(60);
                 }
             }
             fclose($fp);
         }
     } else {
         if (($fp = fopen($this->getDaemonName() . ".lock", "w+")) !== FALSE) {
             if (!flock($fp, LOCK_EX | LOCK_NB)) {
                 $this->info("Batch " . $this->getName() . " was already running.");
                 die("プログラムは既に実行中です。");
             }
             $this->executeImpl($params);
             fclose($fp);
         }
     }
     $this->info("Batch " . $this->getName() . " End.");
 }
示例#8
0
 /**
  * ページ出力用のメソッドをオーバーライドしています。
  * 携帯のページについて、SJISに変換し、カナを半角にしています。
  *
  * @access public
  */
 public function display($template, $cache_id = null, $compile_id = null, $parent = null)
 {
     // キャッシュ無効にするヘッダを送信
     header("P3P: CP='UNI CUR OUR'");
     header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
     header("Last-Modified: " . Vizualizer::now()->gmDate("D, d M Y H:i:s") . " GMT");
     if (array_key_exists("HTTPS", $_SERVER) && $_SERVER['HTTPS'] == 'on') {
         header("Cache-Control: must-revalidate");
         header("Cache-Control: post-check=0, pre-check=0", false);
     } else {
         header("Cache-Control: no-cache, must-revalidate");
         header("Cache-Control: post-check=0, pre-check=0", false);
         header("Pragma: no-cache");
     }
     $attr = Vizualizer::attr();
     $templateEngine = $attr["template"];
     $templateEngine->assign("configure", Vizualizer_Configure::values());
     $templateEngine->assign("post", Vizualizer::request());
     $templateEngine->assign("attr", $attr);
     $templateEngine->assign("session", Vizualizer_Session::values());
     $templateEngine->assign("sessionName", session_name());
     $templateEngine->assign("sessionId", session_id());
     // display template
     Vizualizer_Logger::writeDebug("Template Dir : " . var_export($this->template_dir, true));
     if (Vizualizer_Configure::get("device")->isFuturePhone()) {
         // モバイルの時は出力するHTMLをデータとして取得
         $content = trim($this->core->fetch($template, $cache_id, $compile_id, $parent));
         // カタカナを半角にする。
         $content = mb_convert_kana($content, "k");
         // ソフトバンク以外の場合は、SJISエンコーディングに変換
         if (Vizualizer_Configure::get("device")->getDeviceType() != "Softbank") {
             header("Content-Type: text/html; charset=Shift_JIS");
             if (preg_match("/<meta\\s+http-equiv\\s*=\\s*\"Content-Type\"\\s+content\\s*=\\s*\"([^;]+);\\s*charset=utf-8\"\\s*\\/?>/i", $content, $params) > 0) {
                 header("Content-Type: " . $params[1] . "; charset=Shift_JIS");
                 $content = str_replace($params[0], "<meta http-equiv=\"Content-Type\" content=\"" . $params[1] . "; charset=Shift_JIS\" />", $content);
             } else {
                 header("Content-Type: text/html; charset=Shift_JIS");
             }
             echo mb_convert_encoding($content, "Shift_JIS", "UTF-8");
         } else {
             header("Content-Type: text/html; charset=UTF-8");
             echo $content;
         }
     } else {
         header("Content-Type: text/html; charset=UTF-8");
         echo trim($this->fetch($template, $cache_id, $compile_id, $parent));
     }
 }