Source for file SC_Helper_PageLayout.php

Documentation is available at SC_Helper_PageLayout.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. /**
  25.  * Webページのレイアウト情報を制御するヘルパークラス.
  26.  *
  27.  * @package Helper
  28.  * @author LOCKON CO.,LTD.
  29.  * @version $Id:SC_Helper_PageLayout.php 15532 2007-08-31 14:39:46Z nanasess $
  30.  */
  31.  
  32.     // }}}
  33.     // {{{ functions
  34.  
  35.     /**
  36.      * ページのレイアウト情報をセットする.
  37.      *
  38.      * LC_Page オブジェクトにページのレイアウト情報をセットする.
  39.      *
  40.      * @param LC_Page $objPage ページ情報
  41.      * @param boolean $preview プレビュー表示の場合 true
  42.      * @param string $url ページのURL
  43.      * @return void 
  44.      */
  45.     function sfGetPageLayout(&$objPage$preview false$url ""){
  46.         $debug_message "";
  47.         $arrPageLayout array();
  48.  
  49.         // 現在のURLの取得
  50.         if ($preview === false{
  51.             if ($url == ""{
  52.                 $url "http://" $_SERVER['HTTP_HOST'$_SERVER['PHP_SELF'];
  53.             }
  54.             $url2 preg_replace('|^' preg_quote(SITE_URL'|'''$url);
  55.             // URLを元にページデザインを取得
  56.             $arrPageData $this->lfgetPageData("url IN (?, ?) AND page_id <> 0" array($url2$url))// $url は従来互換
  57.         else {
  58.             $arrPageData $this->lfgetPageData("page_id = 0");
  59.             $objPage->tpl_mainpage USER_PATH "templates/preview/"
  60.                 . TEMPLATE_NAME "/" $arrPageData[0]['filename'".tpl";
  61.         }
  62.         
  63.         foreach($arrPageData[0as $key => $val{
  64.             $debug_message.= "arrPageData[$key]:$val "\n";
  65.         }
  66.         
  67.         $debug_message.= "TEMPLATE_NAME:".TEMPLATE_NAME "\n";
  68.         
  69.         // tpl_mainpageの設定なし、又はトップページの場合
  70.         if (!isset($objPage->tpl_mainpage|| $url == "index.php"{
  71.             // ユーザテンプレートのパスを取得
  72.             $user_tpl =  HTML_PATH USER_DIR USER_PACKAGE_DIR TEMPLATE_NAME "/" $arrPageData[0]['filename'".tpl";
  73.             $debug_message.= "ユーザテンプレートチェック:".$user_tpl."\n";
  74.             
  75.             // ユーザテンプレートの存在チェック
  76.             if (is_file($user_tpl)) {
  77.                 $objPage->tpl_mainpage $user_tpl;
  78.                 $debug_message.= "tpl_mainpage:ユーザーテンプレート\n";
  79.             // 存在しない場合は指定テンプレートを使用
  80.             else {
  81.                 $objPage->tpl_mainpage TEMPLATE_DIR $arrPageData[0]['filename'".tpl";
  82.                 $debug_message.= "tpl_mainpage:標準テンプレート\n";
  83.             }
  84.         else {
  85.             $debug_message.= "tpl_mainpage:設定あり" "\n";
  86.         }
  87.         
  88.         $debug_message.= "tpl_mainpage:" $objPage->tpl_mainpage "\n";
  89.  
  90.         // ページタイトルを設定
  91.         if (!isset($objPage->tpl_title)) {
  92.             $objPage->tpl_title $arrPageData[0]['page_name'];
  93.         }
  94.  
  95.         $arrPageLayout $arrPageData[0];
  96.  
  97.         // 全ナビデータを取得する
  98.         $arrNavi $this->lfGetNaviData($arrPageLayout['page_id']);
  99.  
  100.         $arrPageLayout['LeftNavi']  $this->lfGetNavi($arrNavi,1);    // LEFT NAVI
  101.         $arrPageLayout['MainHead']  $this->lfGetNavi($arrNavi,2);    // メイン上部
  102.         $arrPageLayout['RightNavi'$this->lfGetNavi($arrNavi,3);    // RIGHT NAVI
  103.         $arrPageLayout['MainFoot']  $this->lfGetNavi($arrNavi,4);    // メイン下部
  104.  
  105.         GC_Utils::gfDebugLog($arrPageLayout);
  106.         
  107.         $objPage->arrPageLayout $arrPageLayout;
  108.         
  109.         // カラム数を取得する
  110.         $objPage->tpl_column_num $this->lfGetColumnNum($arrPageLayout);
  111.  
  112.         GC_Utils::gfDebugLog($debug_message);
  113.     }
  114.  
  115.     /**
  116.      * ページ情報を取得する.
  117.      *
  118.      * @param string $where クエリのWHERE句
  119.      * @param array $arrVal WHERE句の条件値
  120.      * @return array ページ情報を格納した配列
  121.      */
  122.     function lfgetPageData($where 'page_id <> 0'$where_vals array()) {
  123.         $objQuery new SC_Query;       // DB操作オブジェクト
  124.         $arrRet array();              // データ取得用
  125.  
  126.         // 取得するカラム
  127.         $col  " page_id";             // ページID
  128.         $col .= " ,page_name";          // 名称
  129.         $col .= " ,url";                // URL
  130.         $col .= " ,php_dir";            // php保存先ディレクトリ
  131.         $col .= " ,tpl_dir";            // tpl保存先ディレクトリ
  132.         $col .= " ,filename";           // ファイル名称
  133.         $col .= " ,header_chk ";        // ヘッダー使用FLG
  134.         $col .= " ,footer_chk ";        // フッター使用FLG
  135.         $col .= " ,edit_flg ";          // 編集可能FLG
  136.         $col .= " ,author";             // authorタグ
  137.         $col .= " ,description";        // descriptionタグ
  138.         $col .= " ,keyword";            // keywordタグ
  139.         $col .= " ,update_url";         // 更新URL
  140.         $col .= " ,create_date";        // データ作成日
  141.         $col .= " ,update_date";        // データ更新日
  142.         
  143.         // 取得するテーブル
  144.         $table "dtb_pagelayout";
  145.         
  146.         // 並び変え
  147.         $objQuery->setOrder('page_id');
  148.         
  149.         // SQL実行
  150.         $arrRet $objQuery->select($col$table$where$where_vals);
  151.         
  152.         // 結果を返す
  153.         return $arrRet;
  154.     }
  155.  
  156.     /**
  157.      * ナビ情報を取得する.
  158.      *
  159.      * @param string $url ページのURL
  160.      * @return array ナビ情報の配列
  161.      */
  162.     function lfGetNaviData($page_id){
  163.         $objQuery new SC_Query;        // DB操作オブジェクト
  164.  
  165.         // 取得するカラム
  166.         $col "target_id, bloc_name, tpl_path, php_path";
  167.         
  168.         // 取得するテーブル
  169.         $table "dtb_blocposition AS pos INNER JOIN dtb_bloc AS bloc ON bloc.bloc_id = pos.bloc_id";
  170.         
  171.         // where文生成
  172.         $where "page_id = ?";
  173.         $where_vals[$page_id;
  174.  
  175.         // 並び変え
  176.         $objQuery->setOrder('target_id, bloc_row');
  177.         
  178.         // SQL実行
  179.         $arrRet $objQuery->select($col$table$where$where_vals);
  180.                                             
  181.         // 結果を返す
  182.         return $arrRet;
  183.     }
  184.  
  185.     /**
  186.      * 各部分のナビ情報を取得する.
  187.      *
  188.      * @param array $arrNavi ナビ情報の配列
  189.      * @param integer|string$target_id ターゲットID
  190.      * @return array ブロック情報の配列
  191.      */
  192.     function lfGetNavi($arrNavi$target_id{
  193.         $arrRet array();
  194.         if(is_array($arrNavi)) {
  195.             foreach($arrNavi as $key => $val){
  196.                 // 指定された箇所と同じデータだけを取得する
  197.                 if ($target_id == $val['target_id']){
  198.                     if ($val['php_path'!= ''{
  199.                         $arrNavi[$key]['php_path'HTML_PATH $val['php_path'];
  200.                     }else{
  201.                         $user_block_path USER_TEMPLATE_PATH TEMPLATE_NAME "/" $val['tpl_path'];
  202.                         if(is_file($user_block_path)) {
  203.                             $arrNavi[$key]['tpl_path'$user_block_path;
  204.                         else {
  205.                             $arrNavi[$key]['tpl_path'TEMPLATE_DIR $val['tpl_path'];
  206.                         }
  207.                     }
  208.                     
  209.                     // phpから呼び出されるか、tplファイルが存在する場合
  210.                     if($val['php_path'!= '' || is_file($arrNavi[$key]['tpl_path'])) {
  211.                         $arrRet[$arrNavi[$key];
  212.                     else {
  213.                         GC_Utils::gfPrintLog("ブロック読み込みエラー:" $arrNavi[$key]['tpl_path']);
  214.                     }
  215.                 }
  216.             }
  217.         }
  218.         return $arrRet;
  219.     }
  220.  
  221.     /**
  222.      * カラム数を取得する.
  223.      * 
  224.      * @param array $arrPageLayout レイアウト情報の配列
  225.      * @return integer $col_num カラム数
  226.      */
  227.     function lfGetColumnNum($arrPageLayout{
  228.         // メインは確定
  229.         $col_num 1;
  230.         // LEFT NAVI
  231.         if (count($arrPageLayout['LeftNavi']0$col_num++;
  232.         // RIGHT NAVI
  233.         if (count($arrPageLayout['RightNavi']0$col_num++;
  234.         
  235.         return $col_num;
  236.     }
  237.  
  238.     /**
  239.      * ページ情報を削除する.
  240.      *
  241.      * @param integer|string$page_id ページID
  242.      * @return integer 削除数
  243.      */
  244.     function lfDelPageData($page_id){
  245.         $objQuery new SC_Query;        // DB操作オブジェクト
  246.         $ret "";                  // 結果格納用
  247.         $arrDelData array();      // 抽出データ用
  248.  
  249.         // page_id が空でない場合にはdeleteを実行
  250.         if ($page_id != ''{
  251.  
  252.             $arrPageData $this->lfgetPageData(" page_id = ? " array($page_id));
  253.             // SQL実行
  254.             $ret $objQuery->delete("dtb_pagelayout""page_id = ?"array($page_id));
  255.  
  256.             // ファイルの削除
  257.             $this->lfDelFile($arrPageData[0]);
  258.         }
  259.         return $ret;
  260.     }
  261.  
  262.     /**
  263.      * ページのファイルを削除する.
  264.      *
  265.      * @param array $arrData ページ情報の配列
  266.      * @return void // TODO boolean にするべき?
  267.      */
  268.     function lfDelFile($arrData){
  269.         // ファイルディレクトリ取得
  270.         $del_php HTML_PATH $arrData['php_dir'$arrData['filename'".php";
  271.         $del_tpl HTML_PATH $arrData['tpl_dir'$arrData['filename'".tpl";
  272.  
  273.         // phpファイルの削除
  274.         if (file_exists($del_php)){
  275.             unlink($del_php);
  276.         }
  277.  
  278.         // tplファイルの削除
  279.         if (file_exists($del_tpl)){
  280.             unlink($del_tpl);
  281.         }
  282.     }
  283.  
  284.     /**
  285.      * データがベースデータかどうか.
  286.      *
  287.      * @param integer|string$data ページID
  288.      * @return boolean ベースデータの場合 true
  289.      */
  290.     function lfCheckBaseData($data){
  291.         $ret false;
  292.  
  293.         if ($data == 0{
  294.             return $ret;
  295.         }
  296.  
  297.         $arrChkData $this->lfgetPageData("page_id = ?"array($data));
  298.  
  299.         if ($arrChkData[0]['edit_flg'== 2){
  300.             $ret true;
  301.         }
  302.  
  303.         return $ret;
  304.     }
  305. }
  306. ?>

Documentation generated on Tue, 28 Apr 2009 18:13:31 +0900 by phpDocumentor 1.4.2