Helper
[ class tree: Helper ] [ index: Helper ] [ all elements ]

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-2010 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.                 // 従来互換(dtb_pagelayoutのurlが絶対URLだった時)
  53.                 $url SITE_URL preg_replace('|^' preg_quote(URL_DIR'|''' $_SERVER['PHP_SELF']);
  54.             }
  55.  
  56.             $url2 preg_replace('|^http://[^/]+' preg_quote(URL_DIR'|'''$url);
  57.             // URLを元にページデザインを取得
  58.             $arrPageData $this->lfgetPageData("url IN (?, ?) AND page_id <> 0" array($url2$url))// $url は従来互換
  59.         else {
  60.             $arrPageData $this->lfgetPageData("page_id = 0");
  61.             $objPage->tpl_mainpage USER_PATH "templates/preview/"
  62.                 . TEMPLATE_NAME "/" $arrPageData[0]['filename'".tpl";
  63.         }
  64.         
  65.         reset($arrPageData[0]);
  66.         whilelist($key,$valeach($arrPageData[0]) ){
  67.             $debug_message.= "arrPageData[$key]:$val "\n";
  68.         }
  69.         
  70.         $debug_message.= "TEMPLATE_NAME:".TEMPLATE_NAME "\n";
  71.         
  72.         // tpl_mainpageの設定なし、又はトップページの場合
  73.         if (!isset($objPage->tpl_mainpage|| $url == "index.php"{
  74.             // ユーザテンプレートのパスを取得
  75.             $user_tpl =  HTML_PATH USER_DIR USER_PACKAGE_DIR TEMPLATE_NAME "/" $arrPageData[0]['filename'".tpl";
  76.             $debug_message.= "ユーザテンプレートチェック:".$user_tpl."\n";
  77.             
  78.             // ユーザテンプレートの存在チェック
  79.             if (is_file($user_tpl)) {
  80.                 $objPage->tpl_mainpage $user_tpl;
  81.                 $debug_message.= "tpl_mainpage:ユーザーテンプレート\n";
  82.             // 存在しない場合は指定テンプレートを使用
  83.             else {
  84.                 $objPage->tpl_mainpage TEMPLATE_DIR $arrPageData[0]['filename'".tpl";
  85.                 $debug_message.= "tpl_mainpage:標準テンプレート\n";
  86.             }
  87.         else {
  88.             $debug_message.= "tpl_mainpage:設定あり" "\n";
  89.         }
  90.         
  91.         $debug_message.= "tpl_mainpage:" $objPage->tpl_mainpage "\n";
  92.  
  93.         // ページタイトルを設定
  94.         if (!isset($objPage->tpl_title)) {
  95.             $objPage->tpl_title $arrPageData[0]['page_name'];
  96.         }
  97.  
  98.         $arrPageLayout $arrPageData[0];
  99.  
  100.         // 全ナビデータを取得する
  101.         $arrNavi $this->lfGetNaviData($arrPageLayout['page_id']);
  102.  
  103.         $arrPageLayout['LeftNavi']  $this->lfGetNavi($arrNavi,1);    // LEFT NAVI
  104.         $arrPageLayout['MainHead']  $this->lfGetNavi($arrNavi,2);    // メイン上部
  105.         $arrPageLayout['RightNavi'$this->lfGetNavi($arrNavi,3);    // RIGHT NAVI
  106.         $arrPageLayout['MainFoot']  $this->lfGetNavi($arrNavi,4);    // メイン下部
  107.  
  108.         GC_Utils::gfDebugLog($arrPageLayout);
  109.         
  110.         $objPage->arrPageLayout $arrPageLayout;
  111.         
  112.         // カラム数を取得する
  113.         $objPage->tpl_column_num $this->lfGetColumnNum($arrPageLayout);
  114.  
  115.         GC_Utils::gfDebugLog($debug_message);
  116.     }
  117.  
  118.     /**
  119.      * ページ情報を取得する.
  120.      *
  121.      * @param string $where クエリのWHERE句
  122.      * @param array $arrVal WHERE句の条件値
  123.      * @return array ページ情報を格納した配列
  124.      */
  125.     function lfgetPageData($where 'page_id <> 0'$where_vals array()) {
  126.         $objQuery new SC_Query;       // DB操作オブジェクト
  127.         $arrRet array();              // データ取得用
  128.  
  129.         // 取得するカラム
  130.         $col  " page_id";             // ページID
  131.         $col .= " ,page_name";          // 名称
  132.         $col .= " ,url";                // URL
  133.         $col .= " ,php_dir";            // php保存先ディレクトリ
  134.         $col .= " ,tpl_dir";            // tpl保存先ディレクトリ
  135.         $col .= " ,filename";           // ファイル名称
  136.         $col .= " ,header_chk ";        // ヘッダー使用FLG
  137.         $col .= " ,footer_chk ";        // フッター使用FLG
  138.         $col .= " ,edit_flg ";          // 編集可能FLG
  139.         $col .= " ,author";             // authorタグ
  140.         $col .= " ,description";        // descriptionタグ
  141.         $col .= " ,keyword";            // keywordタグ
  142.         $col .= " ,update_url";         // 更新URL
  143.         $col .= " ,create_date";        // データ作成日
  144.         $col .= " ,update_date";        // データ更新日
  145.         
  146.         // 取得するテーブル
  147.         $table "dtb_pagelayout";
  148.         
  149.         // 並び変え
  150.         $objQuery->setOrder('page_id');
  151.         
  152.         // SQL実行
  153.         $arrRet $objQuery->select($col$table$where$where_vals);
  154.         
  155.         // 結果を返す
  156.         return $arrRet;
  157.     }
  158.  
  159.     /**
  160.      * ナビ情報を取得する.
  161.      *
  162.      * @param string $url ページのURL
  163.      * @return array ナビ情報の配列
  164.      */
  165.     function lfGetNaviData($page_id){
  166.         $objQuery new SC_Query;   // DB操作オブジェクト
  167.  
  168.         // 取得するカラム
  169.         $col "target_id, bloc_name, tpl_path, php_path";
  170.         
  171.         // 取得するテーブル
  172.         $table "dtb_blocposition AS pos INNER JOIN dtb_bloc AS bloc ON bloc.bloc_id = pos.bloc_id";
  173.         
  174.         // where文生成
  175.         $where "page_id = ?";
  176.         $where_vals[$page_id;
  177.  
  178.         // 並び変え
  179.         $objQuery->setOrder('target_id, bloc_row');
  180.         
  181.         // SQL実行
  182.         $arrRet $objQuery->select($col$table$where$where_vals);
  183.         
  184.         // 結果を返す
  185.         return $arrRet;
  186.     }
  187.  
  188.     /**
  189.      * 各部分のナビ情報を取得する.
  190.      *
  191.      * @param array $arrNavi ナビ情報の配列
  192.      * @param integer|string$target_id ターゲットID
  193.      * @return array ブロック情報の配列
  194.      */
  195.     function lfGetNavi($arrNavi$target_id{
  196.         $arrRet array();
  197.         if(is_array($arrNavi=== true{
  198.             reset($arrNavi);
  199.             whilelist($key,$val)each($arrNavi) ){
  200.                 // 指定された箇所と同じデータだけを取得する
  201.                 if ($target_id == $val['target_id']){
  202.                     if ($val['php_path'!= ''{
  203.                         $arrNavi[$key]['php_path'HTML_PATH $val['php_path'];
  204.                     else {
  205.                         $user_block_path USER_TEMPLATE_PATH TEMPLATE_NAME "/" $val['tpl_path'];
  206.                         if(is_file($user_block_path)) {
  207.                             $arrNavi[$key]['tpl_path'$user_block_path;
  208.                         else {
  209.                             $arrNavi[$key]['tpl_path'TEMPLATE_DIR $val['tpl_path'];
  210.                         }
  211.                     }
  212.                     
  213.                     // phpから呼び出されるか、tplファイルが存在する場合
  214.                     if($val['php_path'!= '' || is_file($arrNavi[$key]['tpl_path'])) {
  215.                         $arrRet[$arrNavi[$key];
  216.                     else {
  217.                         GC_Utils::gfPrintLog("ブロック読み込みエラー:" $arrNavi[$key]['tpl_path']);
  218.                     }
  219.                 }
  220.             }
  221.         }
  222.         return $arrRet;
  223.     }
  224.  
  225.     /**
  226.      * カラム数を取得する.
  227.      * 
  228.      * @param array $arrPageLayout レイアウト情報の配列
  229.      * @return integer $col_num カラム数
  230.      */
  231.     function lfGetColumnNum($arrPageLayout{
  232.         // メインは確定
  233.         $col_num 1;
  234.         // LEFT NAVI
  235.         if (count($arrPageLayout['LeftNavi']0$col_num++;
  236.         // RIGHT NAVI
  237.         if (count($arrPageLayout['RightNavi']0$col_num++;
  238.         
  239.         return $col_num;
  240.     }
  241.  
  242.     /**
  243.      * ページ情報を削除する.
  244.      *
  245.      * @param integer|string$page_id ページID
  246.      * @return integer 削除数
  247.      */
  248.     function lfDelPageData($page_id){
  249.         // DBへデータを更新する
  250.         $objQuery new SC_Query;   // DB操作オブジェクト
  251.         $ret "";                  // 結果格納用
  252.         $arrDelData array();      // 抽出データ用
  253.  
  254.         // page_id が空でない場合にはdeleteを実行
  255.         if ($page_id != ''{
  256.  
  257.             $arrPageData $this->lfgetPageData(" page_id = ? " array($page_id));
  258.             // SQL実行
  259.             $ret $objQuery->delete("dtb_pagelayout""page_id = ?"array($page_id));
  260.  
  261.             // ファイルの削除
  262.             $this->lfDelFile($arrPageData[0]);
  263.         }
  264.         return $ret;
  265.     }
  266.  
  267.     /**
  268.      * ページのファイルを削除する.
  269.      *
  270.      * @param array $arrData ページ情報の配列
  271.      * @return void // TODO boolean にするべき?
  272.      */
  273.     function lfDelFile($arrData){
  274.         // ファイルディレクトリ取得
  275.         $del_php HTML_PATH $arrData['php_dir'$arrData['filename'".php";
  276.         $del_tpl HTML_PATH $arrData['tpl_dir'$arrData['filename'".tpl";
  277.  
  278.         // phpファイルの削除
  279.         if (file_exists($del_php)){
  280.             unlink($del_php);
  281.         }
  282.  
  283.         // tplファイルの削除
  284.         if (file_exists($del_tpl)){
  285.             unlink($del_tpl);
  286.         }
  287.     }
  288.  
  289.     /**
  290.      * データがベースデータかどうか.
  291.      *
  292.      * @param integer|string$data ページID
  293.      * @return boolean ベースデータの場合 true
  294.      */
  295.     function lfCheckBaseData($data){
  296.         $ret false;
  297.  
  298.         if ($data == 0{
  299.             return $ret;
  300.         }
  301.  
  302.         $arrChkData $this->lfgetPageData("page_id = ?"array($data));
  303.  
  304.         if ($arrChkData[0]['edit_flg'== 2){
  305.             $ret true;
  306.         }
  307.  
  308.         return $ret;
  309.     }
  310. }
  311. ?>

Documentation generated on Fri, 24 Feb 2012 14:00:16 +0900 by Seasoft