OSDN Git Service

CKEditorリンク情報プラグイン更新。
authornaoki hirata <naoki@magic3.org>
Mon, 28 Oct 2013 13:18:33 +0000 (22:18 +0900)
committernaoki hirata <naoki@magic3.org>
Mon, 28 Oct 2013 13:18:33 +0000 (22:18 +0900)
scripts/ckeditor4.2.0/plugins/linkinfo/dialogs/linkinfo.js
widgets/admin_main/include/container/admin_mainLinkinfoWidgetContainer.php
widgets/admin_main/include/db/admin_contentDb.php

index 51afd15..05b8a9d 100644 (file)
  * @link       http://www.magic3.org
  */
 CKEDITOR.dialog.add('linkinfoDialog', function(editor){
-       var accessPoint = '0';          // アクセスポイント
+       var accessPoint = '';           // アクセスポイント
        var dialog;                                     // このダイアログへの参照
        
        // コンテンツリスト、コンテンツ内容表示を更新
-       function updateContent()
+       function updateContentList()
        {
+               // コンテンツリストを取得
+               var elementId = '#' + dialog.getContentElement('tab_basic', 'content_list').getInputElement().$.id;
+               var contentType = dialog.getContentElement('tab_basic', 'content_type').getValue();
+               var pageNo = 1;
+
+               // コンテンツプレビュークリア
+               $('#content_text').text('');
+               
+               // Ajaxでページ情報を取得
+               m3_ajax_request('', 'task=linkinfo&act=getcontentlist&contenttype=' + contentType + '&accesspoint=' + accessPoint + '&page=' + pageNo, function(request, retcode, jsondata){            // 正常終了
+                       // コンテンツ種別選択メニューを更新
+                       $('option', elementId).remove();
+                       if (jsondata.contentlist){
+                               $.each(jsondata.contentlist, function(index, item) {
+                                       $(elementId).get(0).options[$(elementId).get(0).options.length] = new Option(item[1], item[0]);
+                               });
+                       }
+               }, function(request){           // 異常終了
+                       alert('通信に失敗しました。');
+               });
+       }
+       
+       // ダイアログ上の項目の表示制御
+       function updateItems()
+       {
+               // リンク対象を取得
+               var selValue = dialog.getValueOf('tab_basic', 'link_target');
+               
+               switch (selValue){
+                       case 'content':
+                               dialog.getContentElement('tab_basic', 'content_type').getElement().show();
+                               dialog.getContentElement('tab_basic', 'content_list').getElement().show();
+                               dialog.getContentElement('tab_basic', 'page').getElement().hide();
+                               dialog.getContentElement('tab_basic', 'content_label').getElement().show();
+                               $('#content_text').show();
+                               break;
+                       case 'page':
+                               dialog.getContentElement('tab_basic', 'content_type').getElement().hide();
+                               dialog.getContentElement('tab_basic', 'content_list').getElement().hide();
+                               dialog.getContentElement('tab_basic', 'page').getElement().show();
+                               dialog.getContentElement('tab_basic', 'content_label').getElement().hide();
+                               $('#content_text').hide();
+                               break;
+                       case 'others':
+                               dialog.getContentElement('tab_basic', 'content_type').getElement().hide();
+                               dialog.getContentElement('tab_basic', 'content_list').getElement().hide();
+                               dialog.getContentElement('tab_basic', 'page').getElement().hide();
+                               dialog.getContentElement('tab_basic', 'content_label').getElement().hide();
+                               $('#content_text').hide();
+                               break;
+               }
+       }
+       // URLを更新。必要項目が選択されていない場合はクリア。
+       function updateUrl()
+       {
+               var url = M3_ROOT_URL + '/index.php';
+               
+               // リンク対象を取得
+               var linkTarget = dialog.getValueOf('tab_basic', 'link_target');
+               switch (linkTarget){
+                       case 'content':
+                               var contentType = dialog.getContentElement('tab_basic', 'content_type').getValue();
+                               var contentId = dialog.getContentElement('tab_basic', 'content_list').getValue();
+
+                               if (contentId){
+                                       switch (contentType){
+                                               case 'content':
+                                               case 'product':
+                                               case 'event':
+                                               case 'photo':
+                                                       url += '?' + contentType + 'id=' + contentId;
+                                                       break;
+                                               case 'blog':
+                                                       url += '?entryid=' + contentId;
+                                                       break;
+                                               case 'wiki':
+                                                       url += '?' + contentId;
+                                                       break;
+                                       }
+                               } else {
+                                       url = '';
+                               }
+                               break;
+                       case 'page':
+                               var pageSubId = dialog.getContentElement('tab_basic', 'page').getValue();
+                               switch (pageSubId){
+                                       case '':
+                                               url = '';
+                                               break;
+                                       case '_root':
+                                               break;
+                                       default:
+                                               url += '?sub=' + pageSubId;
+                                               break;
+                               }
+                               break;
+                       case 'others':
+                               url = '';
+                               break;
+               }
+               dialog.getContentElement('tab_basic', 'url').setValue(url);
        }
        return {
                // Basic properties of the dialog window: title, minimum size.
@@ -32,6 +133,9 @@ CKEDITOR.dialog.add('linkinfoDialog', function(editor){
                        
                        // このダイアログへの参照を取得
                        dialog = this;
+                       
+                       // ダイアログ項目の表示制御
+                       updateItems();
                },
                // Dialog window contents definition.
                contents: [
@@ -52,33 +156,10 @@ CKEDITOR.dialog.add('linkinfoDialog', function(editor){
                                                'default': 'content',
                                                onClick: function(){
                                                        // ダイアログ項目の表示制御
-                                                       var selValue = this.getValue();
-                                                       switch (selValue){
-                                                               case 'content':
-                                                                       dialog.getContentElement('tab_basic', 'content_type').getElement().show();
-                                                                       dialog.getContentElement('tab_basic', 'content').getElement().show();
-                                                                       dialog.getContentElement('tab_basic', 'page').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'url').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'content_label').getElement().show();
-                                                                       dialog.getContentElement('tab_basic', 'content_text').getElement().show();
-                                                                       break;
-                                                               case 'page':
-                                                                       dialog.getContentElement('tab_basic', 'content_type').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'content').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'page').getElement().show();
-                                                                       dialog.getContentElement('tab_basic', 'url').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'content_label').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'content_text').getElement().hide();
-                                                                       break;
-                                                               case 'others':
-                                                                       dialog.getContentElement('tab_basic', 'content_type').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'content').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'page').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'url').getElement().show();
-                                                                       dialog.getContentElement('tab_basic', 'content_label').getElement().hide();
-                                                                       dialog.getContentElement('tab_basic', 'content_text').getElement().hide();
-                                                                       break;
-                                                       }
+                                                       updateItems();
+                                                       
+                                                       // URLを更新
+                                                       updateUrl();
                                                }
                                        },
                                        {       // コンテンツ種別選択
@@ -88,9 +169,6 @@ CKEDITOR.dialog.add('linkinfoDialog', function(editor){
                                                items : [
                                                        [ '接続中', '' ]
                                                ],
-                                               setup: function( element ) {
-                                                       alert("setup");
-                                               },
                                                onLoad : function(){            // 起動時イベント
                                                        var elementId = '#' + this.getInputElement().$.id;
 
@@ -103,37 +181,45 @@ CKEDITOR.dialog.add('linkinfoDialog', function(editor){
                                                                                $(elementId).get(0).options[$(elementId).get(0).options.length] = new Option(item[1], item[0]);
                                                                        });
                                                                }
+                                                               
+                                                               // デフォルトのコンテンツリストを取得
+                                                               updateContentList();
                                                        }, function(request){           // 異常終了
                                                                alert('通信に失敗しました。');
                                                        });
                                                },
                                                onChange : function(){  // 選択値変更時イベント
+                                                       // コンテンツリストを更新
+                                                       updateContentList();
                                                }
                                        },
-                                       {       // コンテンツ選択
+                                       {       // コンテンツリスト
                                                type : 'select',
-                                               id : 'content',
+                                               id : 'content_list',
                                                label : editor.lang.linkinfo.content_list_title,
                                                items : [
                                                        [ '接続中', '' ]
                                                ],
-                                               onLoad : function(){            // 起動時イベント
-                                                       var elementId = '#' + this.getInputElement().$.id;
+                                               onChange : function(){  // 選択値変更時イベント
+                                                       // コンテンツプレビュークリア
+                                                       $('#content_text').text('');
+                                                       
+                                                       // コンテンツ内容を取得
+                                                       var contentType = dialog.getContentElement('tab_basic', 'content_type').getValue();
+                                                       var contentId = dialog.getContentElement('tab_basic', 'content_list').getValue();
 
-                                                       // Ajaxでページ情報を取得
-/*                                                     m3_ajax_request('', 'task=linkinfo&act=getcontenttype&accesspoint=' + accessPoint, function(request, retcode, jsondata){                // 正常終了
-                                                               // コンテンツ種別選択メニューを更新
-                                                               $('option', elementId).remove();
-                                                               if (jsondata.contenttype){
-                                                                       $.each(jsondata.contenttype, function(index, item) {
-                                                                               $(elementId).get(0).options[$(elementId).get(0).options.length] = new Option(item[1], item[0]);
-                                                                       });
+                                                       // Ajaxでコンテンツ内容を取得
+                                                       m3_ajax_request('', 'task=linkinfo&act=getcontent&contenttype=' + contentType + '&contentid=' + contentId + '&accesspoint=' + accessPoint, function(request, retcode, jsondata){                // 正常終了
+
+                                                               if (jsondata.content){
+                                                                       $('#content_text').text(jsondata.content);
                                                                }
+                                                               
+                                                               // URLを更新
+                                                               updateUrl();
                                                        }, function(request){           // 異常終了
                                                                alert('通信に失敗しました。');
-                                                       });*/
-                                               },
-                                               onChange : function(){  // 選択値変更時イベント
+                                                       });
                                                }
                                        },
                                        {
@@ -144,7 +230,7 @@ CKEDITOR.dialog.add('linkinfoDialog', function(editor){
                                                        [ '接続中', '' ]
                                                ],
                                                onLoad : function(){            // 起動時イベント
-                                                       this.getElement().hide();               // 初期時は項目を隠す
+//                                                     this.getElement().hide();               // 初期時は項目を隠す
                                                        
                                                        var elementId = '#' + this.getInputElement().$.id;
 
@@ -162,48 +248,26 @@ CKEDITOR.dialog.add('linkinfoDialog', function(editor){
                                                        });
                                                },
                                                onChange : function(){  // 選択値変更時イベント
-                                               //      var dialog = this.getDialog();
-                                                       var elementId = '#' + dialog.getContentElement('tab_basic', 'content').getInputElement().$.id;          // コンテンツ選択メニュー
-                                                       var subId = this.getValue();
-
-                                                       // Ajaxでコンテンツ情報を取得
-                                                       m3_ajax_request('', 'task=linkinfo&act=getcontentlist&subid=' + subId, function(request, retcode, jsondata){            // 正常終了
-                                                               // コンテンツ選択メニューを更新
-                                                               if (jsondata.contentlist){
-                                                                       $('option', elementId).remove();
-                                                                       if (jsondata.contentlist.length > 0){
-                                                                               $.each(jsondata.contentlist, function(index, item) {
-                                                                                       $(elementId).get(0).options[$(elementId).get(0).options.length] = new Option(item[1], item[0]);
-                                                                               });
-                                                                               dialog.getContentElement('tab_basic', 'content').getElement().show();           // 項目を表示
-                                                                       } else {
-                                                                               dialog.getContentElement('tab_basic', 'content').getElement().hide();           // 項目を非表示
-                                                                       }
-                                                               }
-                                                       }, function(request){           // 異常終了
-                                                               alert('通信に失敗しました。');
-                                                       });
+                                                       // URLを更新
+                                                       updateUrl();
                                                }
                                        },
                                        {
-                                               type: 'text',
-                                               id: 'url',
-                                               label: editor.lang.linkinfo.url_title,
-                                               width: '100%'
-                                       },
-                                       {
                                                type : 'html',
                                                id: 'content_label',
                                                html : '<label>コンテンツ内容:</label>'
                                        },
                                        {
                                                type: 'html',
-                                               id: 'content_text',
                                                //padding: '5px',
-//                                             label: editor.lang.linkinfo.content_title,
-//                                             labelLayout: 'horizontal',
-                                               html: '<p>' + editor.lang.googlemaps.msgLineInstruction + '</p>'
-                                       }
+                                               html: '<p id="content_text" style="white-space: -moz-pre-wrap; white-space: pre-wrap; word-wrap: break-word;"></p>'
+                                       },
+                                       {
+                                               type: 'text',
+                                               id: 'url',
+                                               label: editor.lang.linkinfo.url_title,
+                                               width: '100%'
+                                       },
                                ]
                        },
                        {
index 8ed207b..4e867d0 100644 (file)
@@ -26,7 +26,9 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
        private $pageList = array();            // ページリスト
        private $contentList = array();         // コンテンツリスト
        private $contentType;           // 主要コンテンツタイプ
+       private $accessPointType;       // アクセスポイント種別
        const DEFAULT_CONTENT_COUNT = 300;              // コンテンツリスト取得数
+       const CONTENT_LENGTH = 300;                     // プレビュー用コンテンツサイズ
                
        /**
         * コンストラクタ
@@ -49,6 +51,9 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
                                                                M3_VIEW_TYPE_EVENT,                             // イベント
                                                                M3_VIEW_TYPE_PHOTO);                            // フォトギャラリー
                $this->langId = $this->gEnv->getDefaultLanguage();
+               $this->accessPointType = array( array('', 'PC用「/」'),
+                                                                               array('m', '携帯用「/m」'),
+                                                                               array('s', 'スマートフォン用「/s」'));        // アクセスポイント種別
        }
        /**
         * テンプレートファイルを設定
@@ -76,19 +81,21 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
        function _assign($request, &$param)
        {
                // 入力値を取得
-               $accessPoint = $request->trimIntValueOf('accesspoint', '0');            // アクセスポイント(0=PC,1=携帯,2=スマートフォン)
-               $accessPoint = intval($accessPoint);
-               if (!in_array($accessPoint, array(0, 1, 2))) $accessPoint = 0;
-               
+//             $accessPoint = $request->trimIntValueOf('accesspoint', '0');            // アクセスポイント(0=PC,1=携帯,2=スマートフォン)
+//             $accessPoint = intval($accessPoint);
+//             if (!in_array($accessPoint, array(0, 1, 2))) $accessPoint = 0;
+               $accessPoint = $request->trimValueOf('accesspoint');
+                               
                switch ($accessPoint){
-                       case 0:                 // PC用
+                       case '':                        // PC用
                        default:
                                $defaultPageId = $this->gEnv->getDefaultPageId();
+                               $accessPoint = '';              // アクセスポイント修正
                                break;
-                       case 1:                 // 携帯用
+                       case 'm':                       // 携帯用
                                $defaultPageId = $this->gEnv->getDefaultMobilePageId();
                                break;
-                       case 2:                 // スマートフォン用
+                       case 's':                       // スマートフォン用
                                $defaultPageId = $this->gEnv->getDefaultSmartphonePageId();
                                break;
                }
@@ -106,11 +113,13 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
                        $contentTypeList = $this->getContentTypeList($accessPoint);
                        $this->gInstance->getAjaxManager()->addData('contenttype', $contentTypeList);
                } else if ($act == 'getcontentlist'){           // コンテンツ一覧取得
-                       $pageSubId = $request->trimValueOf('subid');                    // ページサブID    ####### 注意 処理ページが換わってしまうので、システムの「sub」パラメータとは重ならないようにする #######
+                       //$pageSubId = $request->trimValueOf('subid');                  // ページサブID    ####### 注意 処理ページが換わってしまうので、システムの「sub」パラメータとは重ならないようにする #######
+                       $contentType = $request->trimValueOf('contenttype');
+                       $pageNo = $request->trimIntValueOf('page', '1');
 
                        // ページ属性取得
-                       $ret = $this->db->getPageInfo($defaultPageId, $pageSubId, $row);
-                       if ($ret) $contentType = $row['pn_content_type'];
+                       //$ret = $this->db->getPageInfo($defaultPageId, $pageSubId, $row);
+                       //if ($ret) $contentType = $row['pn_content_type'];
                        
                        // コンテンツタイプで一覧を取得
                        $pageNo = 1;            // ページ番号
@@ -118,14 +127,14 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
                                case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツ
                                        // コンテンツタイプ
                                        switch ($accessPoint){
-                                               case 0:                 // PC用
+                                               case '':                        // PC用
                                                default:
                                                        $contentType = '';
                                                        break;
-                                               case 1:                 // 携帯用
+                                               case 'm':                       // 携帯用
                                                        $contentType = 'mobile';
                                                        break;
-                                               case 2:                 // スマートフォン用
+                                               case 's':                       // スマートフォン用
                                                        $contentType = 'smartphone';
                                                        break;
                                        }
@@ -148,14 +157,71 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
                                case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
                                        break;
                        }
-                       
+
                        if (!empty($this->contentList)) $this->contentList = array_merge(array(array('', '-- 未選択 --')), $this->contentList);
                        $this->gInstance->getAjaxManager()->addData('contentlist', $this->contentList);
+               } else if ($act == 'getcontent'){               // コンテンツ取得
+                       $contentType = $request->trimValueOf('contenttype');
+                       $contentId = $request->trimValueOf('contentid');
+                       $contentText = '';              // プレビュー用コンテンツ
+                       
+                       switch ($contentType){
+                               case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツ
+                                       // コンテンツタイプ
+                                       switch ($accessPoint){
+                                               case '':                        // PC用
+                                               default:
+                                                       $contentType = '';
+                                                       break;
+                                               case 'm':                       // 携帯用
+                                                       $contentType = 'mobile';
+                                                       break;
+                                               case 's':                       // スマートフォン用
+                                                       $contentType = 'smartphone';
+                                                       break;
+                                       }
+                                       $ret = $this->contentDb->getContentByContentId($contentType, $contentId, $this->langId, $row);
+                                       if ($ret){
+                                               $contentText = $this->gInstance->getTextConvManager()->htmlToText($row['cn_html']);
+               
+                                               // アプリケーションルートを変換
+                                               $rootUrl = $this->getUrl($this->gEnv->getRootUrl());
+                                               $contentText = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $rootUrl, $contentText);
+               
+                                               // 登録したキーワードを変換
+                                               $this->gInstance->getTextConvManager()->convByKeyValue($contentText, $contentText);
+               
+                                               // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
+                                               $contentText = str_replace(array("\r", "\n", "\t", " "), '', $contentText);
+               
+                                               // 文字列長を修正
+                                               if (function_exists('mb_strimwidth')){
+                                                       $contentText = mb_strimwidth($contentText, 0, self::CONTENT_LENGTH, '…');
+                                               } else {
+                                                       $contentText = substr($contentText, 0, self::CONTENT_LENGTH) . '...';
+                                               }
+                                       }
+                                       break;
+                               case M3_VIEW_TYPE_PRODUCT:      // 製品
+                                       break;
+                               case M3_VIEW_TYPE_BBS:  // BBS
+                                       break;
+                               case M3_VIEW_TYPE_BLOG: // ブログ
+                                       $this->contentDb->getEntryList($this->langId, self::DEFAULT_CONTENT_COUNT, $pageNo, array($this, 'contentLoop'));
+                                       break;
+                               case M3_VIEW_TYPE_WIKI: // Wiki
+                                       break;
+                               case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
+                                       break;
+                               case M3_VIEW_TYPE_EVENT:        // イベント
+                                       break;
+                               case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
+                                       break;
+                       }
+                       $this->gInstance->getAjaxManager()->addData('content', $contentText);
+                       
                } else if ($act == 'getaccesspoint'){           // アクセスポイント取得
-                       $accessPointList = array(       array('0', 'PC用「/」'),
-                                                                               array('1', '携帯用「/m」'),
-                                                                               array('2', 'スマートフォン用「/s」'));
-                       $this->gInstance->getAjaxManager()->addData('accesspoint', $accessPointList);
+                       $this->gInstance->getAjaxManager()->addData('accesspoint', $this->accessPointType);
                }
        }
        /**
@@ -195,8 +261,8 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
        /**
         * コンテンツ種別情報を取得
         *
-        * @param int $accessPoint      アクセスポイント(0=PC、1=携帯、2=スマートフォン)
-        * @return array                        コンテンツ種別情報
+        * @param string $accessPoint   アクセスポイント(「」=PC、「m」=携帯、「s」=スマートフォン)
+        * @return array                                コンテンツ種別情報
         */
        function getContentTypeList($accessPoint)
        {
@@ -225,7 +291,12 @@ class admin_mainLinkinfoWidgetContainer extends admin_mainBaseWidgetContainer
                        }
                }
                $contentTypeList = array();
-               $contentType = $contentTypeArray[$accessPoint];
+               for ($i = 0; $i < count($this->accessPointType); $i++){
+                       if ($this->accessPointType[$i][0] == $accessPoint) break;
+               }
+               if ($i == count($this->accessPointType)) return $contentTypeList;
+               $contentType = $contentTypeArray[$i];
+               
                for ($i = 0; $i < count($contentType); $i++){
                        $contentTypeList[] = array($contentType[$i]['wd_type'], $contentType[$i]['ls_value']);
                }
index c5375ed..a064f4b 100644 (file)
@@ -52,6 +52,25 @@ class admin_contentDb extends BaseDb
                $this->selectLoop($queryStr, $params, $callback);
        }
        /**
+        * コンテンツ項目をコンテンツIDで取得
+        *
+        * @param string  $contentType          コンテンツタイプ
+        * @param string        $contentId              コンテンツID
+        * @param string        $langId                 言語ID
+        * @param array     $row                        レコード
+        * @return bool                                         取得 = true, 取得なし= false
+        */
+       function getContentByContentId($contentType, $contentId, $langId, &$row)
+       {
+               $queryStr  = 'SELECT * FROM content LEFT JOIN _login_user ON cn_create_user_id = lu_id AND lu_deleted = false ';
+               $queryStr .=   'WHERE cn_deleted = false ';     // 削除されていない
+               $queryStr .=    'AND cn_type = ? ';
+               $queryStr .=   'AND cn_id = ? ';
+               $queryStr .=   'AND cn_language_id = ? ';
+               $ret = $this->selectRecord($queryStr, array($contentType, $contentId, $langId), $row);
+               return $ret;
+       }
+       /**
         * ブログ記事一覧を取得
         *
         * @param string        $langId                         言語