OSDN Git Service

キャラクター検索画面に備考表示
authorCake <cake_67@users.sourceforge.jp>
Fri, 10 Dec 2010 05:21:40 +0000 (14:21 +0900)
committerCake <cake_67@users.sourceforge.jp>
Fri, 10 Dec 2010 05:21:40 +0000 (14:21 +0900)
app/views/elements/character_search.ctp
app/views/helpers/profiledisp.php
app/webroot/css/character-sheet.css

index 2c8cccd..f9ee946 100644 (file)
@@ -86,6 +86,7 @@ echo $this->element(
 <?php if (empty($userSet)): ?>
        <th><?php __('User Name');?></th>
 <?php endif; ?>
+       <th class="Notes"><?php __('Notes');?></th>
        <th><?php __('Modified');?></th>
 </tr>
 <?php
@@ -167,6 +168,9 @@ foreach ($characters as $character):
 </td>
 <?php endif; ?>
 <td>
+       <?php echo $profiledisp->multi_truncate($character['Character']['notes']); ?>
+</td>
+<td>
        <?php echo $time->niceShort($character['Character']['modified'], array('format' => 'Y/m/d H:i')); ?>
 </td>
 </tr>
index e3dd1a9..aed7a3f 100644 (file)
@@ -1008,5 +1008,85 @@ class ProfiledispHelper extends Helper {
                return $this->Html->tag('tr', $tds, $tr_options);
        }
 
+
+       /* 一定の文字数で複数行に折り返すtruncate
+        * マルチバイト対応
+        * URLやタグはスキップしない
+        * @param array $options is for truncate()
+        */
+       function multi_truncate($text, $length = 20, $rows = 3, $options = array())
+       {
+               if (empty($text)) {
+                       return $text;
+               }
+
+               $rows = (int)$rows;
+               if (!($rows > 0)) {
+                       $rows = 1;
+               }
+
+               // 置換
+               $replace_pairs = array(
+                       // 改行
+                       '<br>' => "\n",
+                       '<br />' => "\n",
+                       // スペースの連続
+                       "\s\s" => "\s",
+                       ' ' => '',
+               );
+               $text = strtr($text, $replace_pairs);
+
+               // Sanitize戻し
+               $Sanitize = CorePlus::set_behavoir('SanitizePlus');
+               $text = $Sanitize->restore_html($this->model(), $text);
+
+               $text = trim($text);
+
+               if (mb_strlen($text) < $length) {
+                       return $text;
+               }
+
+               // 複数行対応
+               $result = array();
+               $last_row = '';
+               for ($i = 1; $i <= $rows; $i++) {
+                       if ($i > 1) {
+                               if (!$text) {
+                                       break;
+                               }
+
+                               // 前行の分を切り取り
+                               if (!empty($last_row)) {
+                                       $text = substr_replace($text, '', 0, strlen($last_row));
+                               }
+                       }
+                       if ($i == $rows) {
+                               $text_len = mb_strlen($text);
+
+                               if ($text_len < $length) {
+                                       $result[$i] = $text;
+                               } else {
+                                       $result[$i] = $this->Text->truncate($text, mb_strlen(mb_substr($text, 0, $length)), $options);
+                               }
+
+                               break;
+                       } else {
+                               $result[$i] = mb_substr($text, 0, $length);
+                       }
+
+                       $last_row = $result[$i];
+                       $result[$i] = strip_tags($result[$i]);
+
+
+                       // タグをエスケープ
+                       $result[$i] = $Sanitize->escapeTags($this->model(), $result[$i]);
+               }
+
+               $text = implode("<br />\n", $result);
+
+               return $text;
+       }
+
+
 }
 
index 1641a6d..a1c226e 100644 (file)
@@ -209,6 +209,10 @@ div.image div.action li {
 }
 
 /* キャラクター一覧 */
+th.Notes {
+       width: 220px;
+}
+
 #Characters_admin_index table th,
 #Characters_index table th,
 #Characters_mycharacter table th,