public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false) { $attributes = Vizualizer::attr(); // 標準で使用できるパラメータを登録 $templateEngine = $attributes["template"]; $templateEngine->assign("configure", Vizualizer_Configure::values()); $templateEngine->assign("post", Vizualizer::request()); $templateEngine->assign("attr", $attributes); $templateEngine->assign("session", Vizualizer_Session::values()); $templateEngine->assign("sessionName", session_name()); $templateEngine->assign("sessionId", session_id()); // リソースの利用を判定 $prefix = substr($template, 0, strpos($template, ":")); if (ctype_alpha($prefix) && $prefix != "file") { return $this->core->fetch($template, $cache_id, $compile_id, $parent, $display); } else { if (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . "/" . $template)) { return $this->core->fetch($template, $cache_id, $compile_id, $parent, $display); } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . "/err404.html")) { return $this->core->fetch("err404.html", $cache_id, $compile_id, $parent, $display); } else { header("HTTP/1.0 404 Not Found"); echo "ファイルが存在しません。"; exit; } } }
function execute($params) { // リクエストを取得 $attr = Vizualizer::attr(); $geocoder = new Vizualizer_Geocoding_Google($params->get("lang", "en")); $attr[$params->get("result", "geocoder")] = $geocoder; }
function execute($params) { // パラメータを調整 $post = Vizualizer::request(); $month = $post["ym"]; if (empty($month) || preg_match("/[0-9]{4}-[0-9]{2}/", $month) == 0) { $month = date("Y-m"); } // クエリを生成 $loader = new Vizualizer_Plugin("stock"); $orders = $loader->loadTable("Orders"); $select = new Vizualizer_Query_Select($orders); $select->addColumn("SUBSTR(" . $orders->order_date . ", 1, 10)", "order_date"); $select->addColumn("SUM(" . $orders->price . ")", "price"); $select->where("order_date LIKE ?", array($month . "-%")); $select->group("SUBSTR(" . $orders->order_date . ", 1, 10)"); // 生成したクエリに対して検索を実行し、結果をモデルとして取得 $order = $loader->loadModel("Order"); $orders = $order->queryAllBy($select); // 結果を属性に設定 $attr = Vizualizer::attr(); $attr["sales"] = $orders; $attr["thismonth"] = date("Y-m-01", strtotime($month . "-01")); $attr["nextmonth"] = date("Y-m", strtotime("+1 month", strtotime($month . "-01"))); $attr["lastmonth"] = date("Y-m", strtotime("-1 month", strtotime($month . "-01"))); }
function execute($params) { $attr = Vizualizer::attr(); $errors = $attr[Vizualizer::ERROR_KEY]; if (!empty($errors)) { throw new Vizualizer_Exception_Invalid("", ""); } }
protected function executeImpl($type, $name, $value, $result) { // サイトデータを取得する。 $loader = new Vizualizer_Plugin($type); $model = $loader->loadModel($name); $model->setIgnoreOperator(true); $model->findByPrimaryKey($value); $attr = Vizualizer::attr(); $attr[$result] = $model; }
/** * Smarty {end_session} function plugin * * Type: function<br> * Name: end_session<br> * Purpose: end session module.<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_end_session($params, $template) { // テンプレートに各種変数を割り当て $attr = Vizualizer::attr(); $template = $attr["template"]; $template->assign("configure", Vizualizer_Configure::values()); $template->assign("post", Vizualizer::request()); $template->assign("attr", $attr); $template->assign("sessionName", session_name()); $template->assign("sessionId", session_id()); Vizualizer_Logger::writeDebug("Page Session Ended."); }
function execute($params) { // リクエストを取得 $post = Vizualizer::request(); if ($params->check("key") || $params->check("address")) { $address = $params->get("address", $post[$params->get("key")]); $geocoder = new Vizualizer_Geocoding_Google("ja"); $data = $geocoder->getAddressData($address); $attr = Vizualizer::attr(); $attr[$params->get("result", "geocodes")] = $data["results"]; } }
function execute($params) { $post = Vizualizer::request(); $attr = Vizualizer::attr(); $errors = $attr[Vizualizer::ERROR_KEY]; if (!empty($errors) && ($params->check("url") || $params->check("urlkey"))) { VizualizerSession::set("LAST_ERRORS", array(Vizualizer::ERROR_KEY => $errors, Vizualizer::INPUT_KEY => $post)); if ($params->check("url")) { header("Location: " . $params->get("url")); exit; } else { header("Location: " . $post[$params->get("urlkey")]); exit; } } }
/** * Smarty {inline_css} function plugin * * Type: function<br> * Name: inline_css<br> * Purpose: inline css activate plugin.<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_inline_css($params, $template) { $attr = Vizualizer::attr(); $script = ""; if (!empty($params["href"])) { $script .= "<style"; if (!empty($params["type"])) { $script .= " type=\"" . $params["type"] . "\""; } else { $script .= " type=\"text/css\""; } if (!empty($params["media"])) { $script .= " media=\"" . $params["media"] . "\""; } else { $script .= " media=\"all\""; } $script .= ">\r\n"; if (substr($params["href"], 0, 7) !== "http://" && substr($params["href"], 0, 8) !== "https://") { if (substr($params["href"], 0, 1) !== "/") { $info = pathinfo($attr["templateName"]); $params["href"] = $info["dirname"] . "/" . $params["href"]; } $params["href"] = VIZUALIZER_URL . $params["href"]; } if (class_exists("Memcache") && Vizualizer_Configure::get("memcache_contents") && Vizualizer_Configure::get("memcache") !== "") { // memcacheの場合は静的コンテンツをmemcacheにキャッシュする。 $contents = Vizualizer_Cache_Factory::create("inlineCss_" . urlencode($params["href"])); $data = $contents->export(); if (empty($data)) { if (($buffer = file_get_contents($params["href"])) !== FALSE) { $contents->set("content", $buffer); } $data = $contents->export(); } $script .= $data["content"]; } else { if (($buffer = file_get_contents($params["href"])) !== FALSE) { $script .= $buffer; } } $script .= "\r\n</style>"; } return $script; }
function execute($params) { $post = Vizualizer::request(); $attr = Vizualizer::attr(); if ($params->check("daily")) { $search = $post["search"]; if (empty($search["pre:order_date"])) { $search["pre:order_date"] = date("Y-m-d"); $post->set("search", $search); } $attr["thisday"] = date("Y-m-d", strtotime($search["pre:order_date"])); $attr["lastday"] = date("Y-m-d", strtotime("-1 day", strtotime($attr["thisday"]))); $attr["nextday"] = date("Y-m-d", strtotime("+1 day", strtotime($attr["thisday"]))); } $loader = new Vizualizer_Plugin("stock"); $model = $loader->loadModel("Order"); $attr["total"] = $model->summeryBy("price", $post["search"]); $this->executeImpl($params, "Stock", "Order", $params->get("result", "orders")); }
/** * 静的コンテンツを取得する。 */ protected static function getStaticContents($filter = null) { $attr = Vizualizer::attr(); // 静的コンテンツをキャッシュする。 $contents = Vizualizer_Cache_Factory::create("content" . strtr($attr["userTemplate"] . $attr["templateName"], array("/" => "_"))); $data = $contents->export(); if (empty($data)) { if (($buffer = file_get_contents(Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . $attr["templateName"])) !== FALSE) { $mtime = filemtime(Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . $attr["templateName"]); $contents->set("modified", date("F d Y H:i:s.", $mtime)); if ($filter !== null) { $contents->set("data", $filter($buffer)); } else { $contents->set("data", $buffer); } } $data = $contents->export(); } header("Cache-Control: public"); header("Last-Modified: " . $data["modified"]); return $data["data"]; }
protected function executeImpl($params, $type, $name, $defaultSortKey = "create_time") { $post = Vizualizer::request(); if (!$params->check("search") || isset($post[$params->get("search")])) { $loader = new Vizualizer_Plugin($type); // カテゴリが選択された場合、カテゴリの商品IDのリストを使う $conditions = array(); 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); } $result = $model->getAllBy($conditions, $sortOrder, $sortReverse); $titles = explode(",", $params->get("titles")); $columns = explode(",", $params->get("columns")); $basename = uniqid($type . "_" . $name . "_") . ".csv"; $filename = CLAY_ROOT . DIRECTORY_SEPARATOR . "_uploads" . DIRECTORY_SEPARATOR . $basename; if (($fp = fopen($filename, "w+")) !== FALSE) { // CSVヘッダを出力 fwrite($fp, mb_convert_encoding("\"" . implode("\",\"", $titles) . "\"\r\n", "Shift_JIS", "UTF-8")); while ($data = $result->next()) { // データが0件以上の場合は繰り返し foreach ($columns as $index => $column) { if ($index > 0) { fwrite($fp, ","); } fwrite($fp, "\"" . mb_convert_encoding($data[$column], "Shift_JIS", "UTF-8") . "\""); } fwrite($fp, "\r\n"); } fclose($fp); // 作成したファイルを転送 $info = parse_url($params->get("url", "")); $info["chost"] = $info["host"]; if ($info["scheme"] == "https") { $info["chost"] = "ssl://" . $info["host"]; if (empty($info["port"])) { $info["port"] = "443"; } } elseif ($info["scheme"] == "http") { if (empty($info["port"])) { $info["port"] = "80"; } } $protocol = $info["scheme"]; $chost = $info["chost"]; $host = $info["host"]; $port = $info["port"]; if (($fp = fsockopen($chost, $port)) !== FALSE) { $postdata = ""; $postdata .= "POST " . $info["path"] . " HTTP/1.0\r\n"; $postdata .= "Host: " . $host . "\r\n"; $postdata .= "User-Agent: VIZUALIZER-TRANSFER-CALLER\r\n"; $data = $params->get("data", ""); $data = str_replace("[[filename]]", urlencode($basename), $data); $data = str_replace("[[filepath]]", urlencode($filename), $data); $filesize = filesize($filename); $filecontents = chunk_split(base64_encode(file_get_contents($filename))); $boundary = "TRANSFER-" . sha1(uniqid()); $postdata .= "Content-Type: multipart/form-data; boundary=" . $boundary . "\r\n"; $postdata2 = "--" . $boundary . "\r\n"; $postdata2 .= "Content-Disposition: form-data; name=\"" . $params->get("file_key", "FILE") . "_input\"\r\n"; $postdata2 .= "Content-Length: " . strlen($data) . "\r\n"; $postdata2 .= "\r\n"; $postdata2 .= $data . "\r\n"; $postdata2 .= "\r\n--" . $boundary . "\r\n"; $postdata2 .= "Content-Type: text/csv\r\n"; $postdata2 .= "Content-Disposition: form-data; name=\"" . $params->get("file_key", "FILE") . "\"; filename=\"" . $basename . "\"\r\n"; $postdata2 .= "Content-Length: " . strlen($filecontents) . "\r\n"; $postdata2 .= "Content-Transfer-Encoding: base64\r\n"; $postdata2 .= "\r\n"; $postdata2 .= $filecontents; $postdata2 .= "\r\n--" . $boundary . "--"; $postdata .= "Content-Length: " . strlen($postdata2) . "\r\n"; $postdata .= "\r\n" . $postdata2; echo $postdata; fputs($fp, $postdata); $response = ""; while (!feof($fp)) { $response .= fgets($fp, 4096); } fclose($fp); $result = explode("\r\n\r\n", $response, 2); $attr = Vizualizer::attr(); $attr["TransferResult"] = $result[1]; } } } }
/** * 現在表示しようとしているページにリダイレクトします。 * 結果としてリロードする形になります。 */ protected function reload() { $attr = Vizualizer::attr(); $this->redirectInside($attr["templateName"]); }
/** * PDF出力の処理を実行する。 * 出力処理にはHaruを使用します。 * @param $name モデルクラスの名前 * @param $result 出力したファイルのパスを格納するキー */ protected function output($name = "", $result = "") { // 結果のPDFを出力する。 if (!empty($name) && !empty($result)) { // 出力するPDFファイル名を生成 $saveDir = Vizualizer_Configure::get("upload_root") . "/pdf/" . sha1("site" . Vizualizer_Configure::get("site_id")) . "/" . $name . "/"; if (!file_exists($saveDir)) { mkdir($saveDir, 0777, true); } // 保存するファイル名を構築 $saveFile = sha1(uniqid()) . ".pdf"; // 保存するファイルを移動 $this->document->save($saveDir . $saveFile); // 登録した内容をPOSTに設定 $attr = Vizualizer::attr(); $attr[$result] = str_replace(VIZUALIZER_SITE_ROOT, VIZUALIZER_SUBDIR, $saveDir . $saveFile); } else { header("Content-Type: application/pdf"); $this->document->output(); exit; } }
protected function executeImpl($params, $type, $name, $result, $defaultSortKey = "create_time") { $post = Vizualizer::request(); if (!$params->check("search") || isset($post[$params->get("search")])) { $loader = new Vizualizer_Plugin($type); // ページャの初期化 $pagerMode = $params->get("_pager_mode", Vizualizer_Pager::PAGE_SLIDE); $pagerDisplay = $params->get("_pager_dispmode", Vizualizer_Pager::DISPLAY_ATTR); if ($params->check("_pager_per_page_key") && $post[$params->get("_pager_per_page_key")] > 0) { $pagerCount = $post[$params->get("_pager_per_page_key")]; } else { $pagerCount = $params->get("_pager_per_page", 20); } if ($params->check("_pager_displays_key")) { $pagerNumbers = $post[$params->get("_pager_displays_key")]; } else { $pagerNumbers = $params->get("_pager_displays", 3); } $pager = new Vizualizer_Pager($pagerMode, $pagerDisplay, $pagerCount, $pagerNumbers); $pager->importTemplates($params); // カテゴリが選択された場合、カテゴリの商品IDのリストを使う $conditions = $this->condition; if (is_array($post["search"])) { foreach ($post["search"] as $key => $value) { if (!$this->isEmpty($value)) { $conditions[$key] = $value; } } } // 追加の検索条件があれば設定 if ($params->check("wkey")) { $conditions[$params->check("wkey")] = $params->check("wvalue"); } if ($params->check("wkey2")) { $conditions[$params->check("wkey2")] = $params->check("wvalue2"); } if ($params->check("wkey3")) { $conditions[$params->check("wkey3")] = $params->check("wvalue3"); } if ($params->check("wkey4")) { $conditions[$params->check("wkey4")] = $params->check("wvalue4"); } if ($params->check("wkey5")) { $conditions[$params->check("wkey5")] = $params->check("wvalue5"); } if ($params->check("wkey6")) { $conditions[$params->check("wkey6")] = $params->check("wvalue6"); } if ($params->check("wkey7")) { $conditions[$params->check("wkey7")] = $params->check("wvalue7"); } if ($params->check("wkey8")) { $conditions[$params->check("wkey8")] = $params->check("wvalue8"); } if ($params->check("wkey9")) { $conditions[$params->check("wkey9")] = $params->check("wvalue9"); } // 並べ替え順序が指定されている場合に適用 $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; } } elseif ($params->check("sort")) { $sortOrder = $params->check("sort"); if (strpos($sortOrder, "rev@") === 0) { list($dummy, $sortOrder) = explode("@", $sortOrder); $sortReverse = true; } } $model = $loader->LoadModel($name); if ($params->get("force_operator", "0") == "1") { $model->setIgnoreOperator(true); } // 顧客データを検索する。 if (!$this->isEmpty($this->countColumn)) { $pager->setDataSize($model->countBy($conditions, $this->countColumn)); } else { $pager->setDataSize($model->countBy($conditions)); } if ($this->groupBy) { $model->setGroupBy($this->groupBy); } $model->limit($pager->getPageSize(), $pager->getCurrentFirstOffset()); $models = $model->findAllBy($conditions, $sortOrder, $sortReverse); $attr = Vizualizer::attr(); $attr[$result . "_pager"] = $pager; $attr[$result] = $models; } elseif (!$params->check("reset") || isset($post[$params->get("reset")])) { $post["search"] = array(); unset($post[$params->get("reset")]); } }
public static function start() { // REQUEST URIから実際に出力するテンプレートファイルを特定 $attributes = Vizualizer::attr(); $attributes["templateName"] = str_replace("?" . $_SERVER["QUERY_STRING"], "", $_SERVER["REQUEST_URI"]); if (VIZUALIZER_SUBDIR != "") { if (strpos($attributes["templateName"], VIZUALIZER_SUBDIR) === 0) { $attributes["templateName"] = substr($attributes["templateName"], strlen(VIZUALIZER_SUBDIR)); } } // テンプレートにシンボリックリンクを作成する。 if (Vizualizer_Configure::get("site_home") !== null && Vizualizer_Configure::get("site_home") !== "") { if (!is_dir(VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents")) { mkdir(VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents"); } if (!file_exists(VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents" . DIRECTORY_SEPARATOR . Vizualizer_Configure::get("site_domain"))) { Vizualizer_Logger::writeDebug("CREATE SYMBOLIC LINK : " . VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents" . DIRECTORY_SEPARATOR . Vizualizer_Configure::get("site_domain") . " => " . Vizualizer_Configure::get("site_home")); symlink(Vizualizer_Configure::get("site_home"), VIZUALIZER_SITE_ROOT . DIRECTORY_SEPARATOR . "_contents" . DIRECTORY_SEPARATOR . Vizualizer_Configure::get("site_domain")); } if (is_writable(Vizualizer_Configure::get("site_home"))) { if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "mobile")) { symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "default", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "mobile"); } if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone")) { symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "default", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone"); } if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "iphone")) { symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "iphone"); } if (!file_exists(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "android")) { symlink(Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "sphone", Vizualizer_Configure::get("site_home") . DIRECTORY_SEPARATOR . "android"); } } } // ユーザーのテンプレートを取得する。 if (Vizualizer_Configure::get("device") !== null) { if (Vizualizer_Configure::get("device")->isMobile()) { if (Vizualizer_Configure::get("device")->isSmartPhone()) { if (Vizualizer_Configure::get("device")->getDeviceType() == "iPhone") { $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "iphone"; } elseif (Vizualizer_Configure::get("device")->getDeviceType() == "Android") { $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "android"; } $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "sphone"; } else { $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "mobile"; } } else { $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "default"; } } else { $attributes["userTemplate"] = DIRECTORY_SEPARATOR . "default"; } // テンプレートがディレクトリかどうか調べ、ディレクトリの場合はファイル名に落とす。 // 呼び出し先がディレクトリで最後がスラッシュでない場合は最後にスラッシュを補完 if (is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"])) { if (is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"]) && substr($attributes["templateName"], -1) != DIRECTORY_SEPARATOR) { $attributes["templateName"] .= DIRECTORY_SEPARATOR; } if (substr($attributes["templateName"], -1) === DIRECTORY_SEPARATOR) { if (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.html")) { $attributes["templateName"] .= "index.html"; } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.htm")) { $attributes["templateName"] .= "index.htm"; } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.php")) { $attributes["templateName"] .= "index.php"; } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.xml")) { $attributes["templateName"] .= "index.xml"; } else { // いずれも存在しない場合はダミーとしてindex.htmlを設定しておく $attributes["templateName"] .= "index.html"; } } } if (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"]) || is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"])) { if (is_dir(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"]) && substr($attributes["templateName"], -1) != DIRECTORY_SEPARATOR) { $attributes["templateName"] .= DIRECTORY_SEPARATOR; } // 呼び出し先がスラッシュで終わっている場合にはファイル名を補完 if (substr($attributes["templateName"], -1) === DIRECTORY_SEPARATOR) { if (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.html")) { $attributes["templateName"] .= "index.html"; } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.htm")) { $attributes["templateName"] .= "index.htm"; } elseif (file_exists(Vizualizer_Configure::get("site_home") . $attributes["userTemplate"] . $attributes["templateName"] . "index.xml")) { $attributes["templateName"] .= "index.xml"; } else { // いずれも存在しない場合はダミーとしてindex.htmlを設定しておく $attributes["templateName"] .= "index.html"; } } } if (substr($attributes["templateName"], -1) === DIRECTORY_SEPARATOR) { // いずれも存在しない場合はダミーとしてindex.htmlを設定しておく $attributes["templateName"] .= "index.html"; } // テンプレートの存在するパスを取得する。 define("TEMPLATE_DIRECTORY", dirname($attributes["templateName"])); }
/** * Smarty {loadmodule} function plugin * * Type: function<br> * Name: loadmodule<br> * Purpose: load framework module.<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_loadmodule($params, $template) { // nameパラメータは必須です。 if (empty($params['name'])) { trigger_error("loadmodule: missing name parameter", E_USER_WARNING); return; } if (!empty($params["if"])) { $result = true; $expression = '$result = ' . str_replace('_POST', '$_POST', $params["if"]) . ';'; eval($expression); if (!$result) { return; } } // パラメータを変数にコピー $name = $params['name']; // errorパラメータはエラー例外時に指定されたテンプレートに変更する。 if (isset($params["error"])) { $error = $params['error']; } else { $error = ""; } // モジュールのクラスが利用可能か調べる。 $errors = null; try { // モジュール用のクラスをリフレクション list($namespace, $class) = explode(".", $name, 2); $loader = new Vizualizer_Plugin($namespace); $object = $loader->loadModule($class); if (method_exists($object, "start")) { Vizualizer_Logger::writeDebug("=========== " . $name . " start ==========="); // 検索条件と並べ替えキー以外を無効化する。 if (isset($params["clear"]) && $params["clear"] == "1") { if (isset($params["sort_key"]) && !empty($params["sort_key"])) { $_POST = array("search" => $_POST["search"], $params["sort_key"] => $_POST[$params["sort_key"]]); } else { $_POST = array("search" => $_POST["search"]); } } if (!empty($params["key_prefix"])) { $object->key_prefix = $params["key_prefix"]; } else { $object->key_prefix = ""; } if (!empty($params["continue"])) { $object->continue = $params["continue"]; } else { $object->continue = ""; } $object->execute(new Vizualizer_Plugin_Module_Parameters($params)); Vizualizer_Logger::writeDebug("=========== " . $name . " end ==========="); } else { Vizualizer_Logger::writeAlert($name . " is not plugin module."); } } catch (Vizualizer_Exception_Invalid $e) { // 入力エラーなどの例外(ただし、メッセージリストを空にすると例外処理を行わない) Vizualizer_Logger::writeError($e->getMessage(), $e); $errors = $e->getErrors(); } catch (Vizualizer_Exception_Database $e) { // システムエラーの例外処理 Vizualizer_Logger::writeError($e->getMessage(), $e); $errors = array(Vizualizer::ERROR_TYPE_DATABASE => $e->getMessage()); } catch (Vizualizer_Exception_System $e) { // システムエラーの例外処理 Vizualizer_Logger::writeError($e->getMessage(), $e); $errors = array(Vizualizer::ERROR_TYPE_SYSTEM => $e->getMessage()); } catch (Exception $e) { // 不明なエラーの例外処理 Vizualizer_Logger::writeError($e->getMessage(), $e); $errors = array(Vizualizer::ERROR_TYPE_UNKNOWN => $e->getMessage()); } // エラー配列をスタックさせる if (is_array($errors) && !empty($errors)) { $attr = Vizualizer::attr(); // エラー用配列が配列になっていない場合は初期化 $errorData = $attr[Vizualizer::ERROR_KEY]; if (!is_array($errorData)) { $errorData = array(); } // エラー内容をマージさせる。 foreach ($errors as $key => $message) { if ($key != "" && !array_key_exists($key, $errorData)) { $errorData[$key] = $message; } } $templateEngine = $attr["template"]; if (!empty($error)) { // errorパラメータが渡っている場合はスタックさせたエラーを全て出力してエラー画面へ $templateEngine->assign("ERRORS", $errorData); unset($attr[Vizualizer::ERROR_KEY]); $info = pathinfo($error); switch ($info["extension"]) { case "php": // PHPを実行する場合、インクルードパスの最優先をテンプレートのディレクトリに設定 ini_set("include_path", Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . PATH_SEPARATOR . ini_get("include_path")); $source = file_get_contents(Vizualizer_Configure::get("site_home") . $attr["userTemplate"] . DIRECTORY_SEPARATOR . $error); // 先頭のPHPタグを除去 $source = "?>" . $source; // バッファを除去 ob_end_clean(); ob_start(); eval($source); // 実行後のデータを取得し、バッファを再度除去 $source = ob_get_contents(); ob_end_clean(); ob_start(); // ソースデータをリソース化 $source = "eval:" . $source; // テンプレートを表示 $templateEngine->display($source); exit; default: $templateEngine->display($error); exit; } } else { $attr[Vizualizer::ERROR_KEY] = $errorData; } } }
/** * テンプレートで使うことのできるデータをデバッグログに出力 */ protected function logTemplateData() { $attr = Vizualizer::attr(); $template = $attr["template"]; $this->debug("======= CONFIGURE =======", 99); $this->debug(print_r($template->getVars("configure"), true), 99); $this->debug("======= PARAMETER =======", 99); $this->debug(print_r($template->getVars("post")->values(), true), 99); $this->debug("======= SESSIONS =======", 99); $attrs = $template->getVars("session"); foreach ($attrs as $key => $attr) { if ($attr instanceof Vizualizer_Template) { } elseif ($attr instanceof Vizualizer_Plugin_Model) { $this->debug($key . " = " . print_r($attr->toArray(), true), 99); } else { $this->debug($key . " = " . print_r($attr, true), 99); } } $this->debug("======= ATTRIBUTES =======", 99); $attrs = $template->getVars("attr")->values(); foreach ($attrs as $key => $attr) { if ($attr instanceof Vizualizer_Template) { } elseif ($attr instanceof Vizualizer_Plugin_Model) { $this->debug($key . " = " . print_r($attr->toArray(), true), 99); } else { $this->debug($key . " = " . print_r($attr, true), 99); } } }
protected function executeImpl($params, $type, $name, $result, $defaultSortKey = "create_time") { $post = Vizualizer::request(); // セレクトモードの時は通常の検索条件を適用しない if ($params->check("mode", "normal") == "select") { $savedPost = $post->export(); $selectSearch = array(); if ($params->check("selectSearchKeys") && array_key_exists("search", $savedPost) && is_array($savedPost["search"])) { $selectKeys = explode(",", $params->get("selectSearchKeys")); foreach ($selectKeys as $key) { if (array_key_exists($key, $savedPost["search"])) { $selectSearch[$key] = $savedPost["search"][$key]; } } } Vizualizer::request()->set("search", $selectSearch); } if (!$params->check("search") || isset($post[$params->get("search")])) { // サイトデータを取得する。 $loader = new Vizualizer_Plugin($type); $model = $loader->loadModel($name); // カテゴリが選択された場合、カテゴリの商品IDのリストを使う $conditions = $this->condition; if (is_array($post["search"])) { foreach ($post["search"] as $key => $value) { if (!$this->isEmpty($value)) { if ($params->get("mode", "list") != "select" || !$params->check("select") || $key != substr($params->get("select"), 0, strpos($params->get("select"), "|"))) { $conditions[$key] = $value; } } } } // 追加の検索条件があれば設定 if ($params->check("wkey")) { $conditions[$params->check("wkey")] = $params->check("wvalue"); } if ($params->check("wkey2")) { $conditions[$params->check("wkey2")] = $params->check("wvalue2"); } if ($params->check("wkey3")) { $conditions[$params->check("wkey3")] = $params->check("wvalue3"); } if ($params->check("wkey4")) { $conditions[$params->check("wkey4")] = $params->check("wvalue4"); } if ($params->check("wkey5")) { $conditions[$params->check("wkey5")] = $params->check("wvalue5"); } if ($params->check("wkey6")) { $conditions[$params->check("wkey6")] = $params->check("wvalue6"); } if ($params->check("wkey7")) { $conditions[$params->check("wkey7")] = $params->check("wvalue7"); } if ($params->check("wkey8")) { $conditions[$params->check("wkey8")] = $params->check("wvalue8"); } if ($params->check("wkey9")) { $conditions[$params->check("wkey9")] = $params->check("wvalue9"); } $attr = Vizualizer::attr(); if ($this->groupBy) { $model->setGroupBy($this->groupBy); } // 並べ替え順序が指定されている場合に適用 $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; } } elseif ($params->check("sort")) { $sortOrder = $params->check("sort"); if (strpos($sortOrder, "rev@") === 0) { list($dummy, $sortOrder) = explode("@", $sortOrder); $sortReverse = true; } } if ($params->get("force_operator", "0") == "1") { $model->setIgnoreOperator(true); } $models = $model->findAllBy($conditions, $sortOrder, $sortReverse); if ($params->get("mode", "list") == "list") { $attr[$result] = $models; } elseif ($params->get("mode", "list") == "select") { $attr[$result] = array(); if ($params->check("select")) { list($select_key, $select_value) = explode("|", $params->get("select")); $selection = array(); foreach ($models as $model) { $selection[$model->{$select_key}] = $model->{$select_value}; } $attr[$result] = $selection; } } if ($params->check("mode", "normal") == "select") { Vizualizer::request()->import($savedPost); } } }
/** * ページ出力用のメソッドをオーバーライドしています。 * 携帯のページについて、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)); } }