OSDN Git Service

WordPressテンプレート機能更新。
[magic3/magic3.git] / include / wp / WPRender.php
1 <?php
2 /**
3  * WordPressウィジェットHTML作成クラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
9  * @package    Magic3 Framework
10  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11  * @copyright  Copyright 2006-2017 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id$
14  * @link       http://www.magic3.org
15  */
16         
17 class WPRender
18 {
19         const DEFAULT_POSITION = 'sidebar-1';
20         
21         /**
22          * コンストラクタ
23          */
24         function __construct()
25         {
26         }
27         /**
28          * WordPressモジュール用コンテンツ取得
29          * 
30          * @param string $style                 表示スタイル
31          * @param string $content               ウィジェット出力
32          * @param string $title                 タイトル(空のときはタイトル非表示)
33          * @param array $attribs                その他タグ属性
34          * @param array $paramsOther    その他パラメータ
35          * @param array $pageDefParam   画面定義パラメータ
36          * @param int   $templateVer    テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
37          * @param string $widgetTag             ウィジェット識別用タグ
38          * @return string                               モジュール出力
39          */
40         public function getModuleContents($style, $content, $title = '', $attribs = array(), $paramsOther = array(), $pageDefParam = array(), $templateVer = 0, $widgetTag = '')
41         {
42                 global $wp_registered_sidebars;
43
44                 // 現在のポジション取得
45                 $position = $pageDefParam['pd_position_id'];
46                 
47                 // 配置ブロック用のパラメータを取得
48                 $blockParam = $wp_registered_sidebars[$position];
49                 if (empty($blockParam)) $blockParam = $wp_registered_sidebars[self::DEFAULT_POSITION];                  // 存在しない場合はデフォルトを取得
50                 
51                 // WordPress側から初期パラメータを取得できない場合は終了
52                 if (empty($blockParam)) return $content;
53                 
54                 // タイトルを追加
55                 if ($style == PageManager::WIDGET_STYLE_WORDPRESS){                     // タイトルありの場合
56                         if (!empty($title)) $content = $blockParam['before_title'] . convertToHtmlEntity($title) . $blockParam['after_title'] . $content;
57                 }
58                 
59                 // 前後コンテンツ追加
60 //              $content = $pageDefParam['pd_top_content'] . $content . $pageDefParam['pd_bottom_content'];
61                 // 「もっと読む」ボタンを追加
62 //              if ($pageDefParam['pd_show_readmore']) $content = $this->addReadMore($content, $pageDefParam['pd_readmore_title'], $pageDefParam['pd_readmore_url']);
63                 
64                 // コンテンツ全体をウィジェット用タグで囲む
65                 $widgetClass = 'm3widget_' . $pageDefParam['pd_widget_id'];             // ウィジェットIDからクラス名作成
66                 $blockParam['before_widget'] = sprintf($blockParam['before_widget'], $widgetTag, $widgetClass);         // ウィジェット識別用IDとウィジェットクラス名
67                 $content = $blockParam['before_widget'] . $content . $blockParam['after_widget'];
68                  
69                 return $content;
70         }
71         /**
72          * WordPressコンポーネント用コンテンツ取得
73          * 
74          * @param string $style                 表示スタイル
75          * @param string $content               ウィジェット出力
76          * @param string $title                 タイトル(空のときはタイトル非表示)
77          * @param array $attribs                その他タグ属性
78          * @param array $paramsOther    その他パラメータ
79          * @param array $pageDefParam   画面定義パラメータ
80          * @param int   $templateVer    テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
81          * @param string $widgetTag             ウィジェット識別用タグ
82          * @return string                               モジュール出力
83          */
84         public function getComponentContents($style, $content, $title = '', $attribs = array(), $paramsOther = array(), $pageDefParam = array(), $templateVer = 0, $widgetTag = '')
85         {
86                 global $gEnvManager;
87                 global $gContentApi;
88                 
89                 // コンポーネント生成用スクリプトパス取得
90                 $componentPath = $gEnvManager->getWpComponentPath();
91                 if (file_exists($componentPath)){
92                         // ウィジェットで生成されたデータでWordPressコンポーネント用のデータを更新
93                         $gContentApi->updateComponentContent($content);
94                         
95                         ob_clean();
96                         require($componentPath);                // 毎回実行する
97                         $content = ob_get_contents();
98                         ob_clean();
99                 } else {
100                         // コンポーネント生成用スクリプトがない場合はWordPressモジュール出力を使用
101                         $content = $this->getModuleContents($style, $content, $title, $attribs, $paramsOther, $pageDefParam, $templateVer, $widgetTag);
102                 }
103                 return $content;
104         }
105 }
106 ?>