Cloud computing platform
Revisión | b9b00dd8d34ec9a6df7c3b6d54eeb20f9fbb09b1 (tree) |
---|---|
Tiempo | 2019-02-28 08:32:40 |
Autor | naoki hirata <naoki@magi...> |
Commiter | naoki hirata |
ブログ記事から画像ギャラリー用に画像を抜き出す処理を追加。
@@ -8,7 +8,7 @@ | ||
8 | 8 | * |
9 | 9 | * @package Magic3 Framework |
10 | 10 | * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp> |
11 | - * @copyright Copyright 2006-2015 Magic3 Project. | |
11 | + * @copyright Copyright 2006-2019 Magic3 Project. | |
12 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GPL License |
13 | 13 | * @version SVN: $Id$ |
14 | 14 | * @link http://www.magic3.org |
@@ -33,6 +33,8 @@ class ImageManager extends Core | ||
33 | 33 | const PARSE_IMAGE_FORMAT = '/(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマット解析用 |
34 | 34 | // const PARSE_IMAGE_FORMAT_TYPE = '/(.*?)\s*=\s*(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用 |
35 | 35 | const PARSE_IMAGE_FORMAT_TYPE = '/(.*?)\s*=\s*(\d+)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用 |
36 | + const PARSE_IMAGE_TAG = '/<img[^<]*?src\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si'; // HTMLからIMGタグ取得用 | |
37 | + | |
36 | 38 | // DB定義値 |
37 | 39 | // const CF_SITE_LOGO_FILENAME = 'site_logo_filename'; // サイトロゴファイル |
38 | 40 | const CF_SITE_LOGO_FORMAT = 'site_logo_format'; // サイトロゴフォーマット |
@@ -98,7 +100,6 @@ class ImageManager extends Core | ||
98 | 100 | |
99 | 101 | for ($i = 0; $i < count($formatArray); $i++){ |
100 | 102 | $format = trim($formatArray[$i]); |
101 | -// $ret = preg_match('/(\d+)(.*)\.(gif|png|jpg|jpeg|bmp)$/i', $format, $matches); | |
102 | 103 | $ret = $this->parseImageFormat($format, $imageType, $imageAttr, $imageSize, $imageWidthHeight); |
103 | 104 | if ($ret){ |
104 | 105 | $thumbSize = $imageWidthHeight; |
@@ -791,8 +792,7 @@ class ImageManager extends Core | ||
791 | 792 | { |
792 | 793 | global $gEnvManager; |
793 | 794 | |
794 | - $exp = '/<img[^<]*?src\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si'; | |
795 | - $ret = preg_match($exp, $html, $matches); | |
795 | + $ret = preg_match(self::PARSE_IMAGE_TAG, $html, $matches); | |
796 | 796 | if ($ret){ |
797 | 797 | $path = $gEnvManager->getMacroPath($matches[1]); // 画像URL |
798 | 798 | $path = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $gEnvManager->getSystemRootPath(), $path);// マクロ変換 |
@@ -801,6 +801,25 @@ class ImageManager extends Core | ||
801 | 801 | return ''; |
802 | 802 | } |
803 | 803 | /** |
804 | + * コンテンツからサイト内のすべての画像のパスを取得 | |
805 | + * | |
806 | + * @param string $html 検索コンテンツ(画像パスはマクロ変換済み) | |
807 | + * @return array 画像パス(リソースディレクトリからの相対パス) | |
808 | + */ | |
809 | + function getSiteImagePath($html) | |
810 | + { | |
811 | + $imagePaths = array(); | |
812 | + preg_match_all(self::PARSE_IMAGE_TAG, $html, $matches, PREG_SET_ORDER); | |
813 | + for ($i = 0; $i < count($matches); $i++){ | |
814 | + $path = $matches[$i][1]; | |
815 | + if (strStartsWith($path, M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_DIR_NAME_RESOURCE)){ | |
816 | + $path = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_DIR_NAME_RESOURCE, '', $path); | |
817 | + if (!in_array($path, $imagePaths)) $imagePaths[] = $path; | |
818 | + } | |
819 | + } | |
820 | + return $imagePaths; | |
821 | + } | |
822 | + /** | |
804 | 823 | * サイトロゴ画像のURLを取得 |
805 | 824 | * |
806 | 825 | * @param string $type 画像タイプ「sm」「md」「lg」。空の場合はロゴ格納ディレクトリURLを返す。 |
@@ -1214,7 +1233,6 @@ class ImageManager extends Core | ||
1214 | 1233 | function parseImageFormat($format, &$imageType, &$imageAttr, &$imageSize, &$imageWidthHeight = null) |
1215 | 1234 | { |
1216 | 1235 | $format = trim($format); |
1217 | - //$ret = preg_match('/(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i', $format, $matches); // 「MMxNNc.jpg」タイプのフォーマットを解析 | |
1218 | 1236 | $ret = preg_match(self::PARSE_IMAGE_FORMAT, $format, $matches); // 「MMxNNc.jpg」タイプのフォーマットを解析 |
1219 | 1237 | if ($ret){ |
1220 | 1238 | $imageSize = $matches[1]; |
@@ -1262,8 +1280,6 @@ class ImageManager extends Core | ||
1262 | 1280 | for ($i = 0; $i < count($lines); $i++){ |
1263 | 1281 | $line = trim($lines[$i]); |
1264 | 1282 | if (!empty($line)){ |
1265 | - //$ret = preg_match(, $line, $matches); | |
1266 | - //'/(.*?)\s*=\s*(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用 | |
1267 | 1283 | $ret = preg_match(self::PARSE_IMAGE_FORMAT_TYPE, $line, $matches); |
1268 | 1284 | if ($ret){ |
1269 | 1285 | $imageType = $matches[1]; |
@@ -20,8 +20,8 @@ | ||
20 | 20 | |
21 | 21 | -- *** システム標準テーブル *** |
22 | 22 | -- ブログ記事画像マスター |
23 | -DROP TABLE IF EXISTS blog_entry_image; | |
24 | -CREATE TABLE blog_entry_image ( | |
23 | +DROP TABLE IF EXISTS blog_image; | |
24 | +CREATE TABLE blog_image ( | |
25 | 25 | bm_serial INT AUTO_INCREMENT, -- レコードシリアル番号 |
26 | 26 | bm_entry_serial INT DEFAULT 0 NOT NULL, -- ブログ記事シリアル番号 |
27 | 27 | bm_index INT DEFAULT 0 NOT NULL, -- インデックス番号 |
@@ -488,6 +488,11 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta | ||
488 | 488 | $html = $this->gInstance->getTextConvManager()->convToContentMacro($html); |
489 | 489 | $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2); |
490 | 490 | |
491 | + // 記事に含まれるすべての画像のパスを取得 | |
492 | + $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html); | |
493 | + $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2); | |
494 | + $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2)); | |
495 | + | |
491 | 496 | // 追加パラメータ |
492 | 497 | $otherParams = array( 'be_description' => $desc, // 簡易説明 |
493 | 498 | 'be_meta_description' => $metaDesc, // ページ要約(METAタグ) |
@@ -499,10 +504,10 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta | ||
499 | 504 | |
500 | 505 | // 記事データを追加 |
501 | 506 | if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // 多言語でデフォルト言語、または単一言語のとき |
502 | - $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, | |
507 | + $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId, | |
503 | 508 | $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams); |
504 | 509 | } else { |
505 | - $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, | |
510 | + $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId, | |
506 | 511 | $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams); |
507 | 512 | } |
508 | 513 | if ($ret){ |
@@ -621,6 +626,11 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta | ||
621 | 626 | $html = $this->gInstance->getTextConvManager()->convToContentMacro($html); |
622 | 627 | $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2); |
623 | 628 | |
629 | + // 記事に含まれるすべての画像のパスを取得 | |
630 | + $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html); | |
631 | + $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2); | |
632 | + $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2)); | |
633 | + | |
624 | 634 | // 追加パラメータ |
625 | 635 | $otherParams = array( 'be_description' => $desc, // 簡易説明 |
626 | 636 | 'be_meta_description' => $metaDesc, // ページ要約(METAタグ) |
@@ -639,7 +649,7 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta | ||
639 | 649 | } |
640 | 650 | |
641 | 651 | // 記事データを更新 |
642 | - $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, | |
652 | + $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId, | |
643 | 653 | ''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams); |
644 | 654 | /* if ($ret){ |
645 | 655 | // コンテンツに画像がなくなった場合は、サムネールを削除 |
@@ -490,6 +490,11 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer | ||
490 | 490 | $html = $this->gInstance->getTextConvManager()->convToContentMacro($html); |
491 | 491 | $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2); |
492 | 492 | |
493 | + // 記事に含まれるすべての画像のパスを取得 | |
494 | + $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html); | |
495 | + $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2); | |
496 | + $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2)); | |
497 | + | |
493 | 498 | // 追加パラメータ |
494 | 499 | $otherParams = array( 'be_description' => $desc, // 簡易説明 |
495 | 500 | 'be_meta_description' => $metaDesc, // ページ要約(METAタグ) |
@@ -501,10 +506,10 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer | ||
501 | 506 | |
502 | 507 | // 記事データを追加 |
503 | 508 | if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // 多言語でデフォルト言語、または単一言語のとき |
504 | - $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, | |
509 | + $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId, | |
505 | 510 | $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams); |
506 | 511 | } else { |
507 | - $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, | |
512 | + $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId, | |
508 | 513 | $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams); |
509 | 514 | } |
510 | 515 | if ($ret){ |
@@ -623,6 +628,11 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer | ||
623 | 628 | $html = $this->gInstance->getTextConvManager()->convToContentMacro($html); |
624 | 629 | $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2); |
625 | 630 | |
631 | + // 記事に含まれるすべての画像のパスを取得 | |
632 | + $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html); | |
633 | + $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2); | |
634 | + $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2)); | |
635 | + | |
626 | 636 | // 追加パラメータ |
627 | 637 | $otherParams = array( 'be_description' => $desc, // 簡易説明 |
628 | 638 | 'be_meta_description' => $metaDesc, // ページ要約(METAタグ) |
@@ -641,7 +651,7 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer | ||
641 | 651 | } |
642 | 652 | |
643 | 653 | // 記事データを更新 |
644 | - $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, | |
654 | + $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId, | |
645 | 655 | ''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams); |
646 | 656 | /* if ($ret){ |
647 | 657 | // コンテンツに画像がなくなった場合は、サムネールを削除 |
@@ -8,7 +8,7 @@ | ||
8 | 8 | * |
9 | 9 | * @package Magic3 Framework |
10 | 10 | * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp> |
11 | - * @copyright Copyright 2006-2017 Magic3 Project. | |
11 | + * @copyright Copyright 2006-2019 Magic3 Project. | |
12 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GPL License |
13 | 13 | * @version SVN: $Id$ |
14 | 14 | * @link http://www.magic3.org |
@@ -251,6 +251,7 @@ class blog_mainDb extends BaseDb | ||
251 | 251 | * @param string $html2 HTML(続き) |
252 | 252 | * @param int $status エントリー状態(0=未設定、1=編集中、2=公開、3=非公開) |
253 | 253 | * @param array $category カテゴリーID |
254 | + * @param array $images 記事画像 | |
254 | 255 | * @param string $blogId ブログID |
255 | 256 | * @param int $regUserId 投稿者ユーザID |
256 | 257 | * @param timestamp $regDt 投稿日時 |
@@ -262,7 +263,7 @@ class blog_mainDb extends BaseDb | ||
262 | 263 | * @param array $otherParams その他のフィールド値 |
263 | 264 | * @return bool true = 成功、false = 失敗 |
264 | 265 | */ |
265 | - function addEntryItem($id, $langId, $name, $html, $html2, $status, $category, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial, $otherParams = null) | |
266 | + function addEntryItem($id, $langId, $name, $html, $html2, $status, $category, $images, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial, $otherParams = null) | |
266 | 267 | { |
267 | 268 | $now = date("Y/m/d H:i:s"); // 現在日時 |
268 | 269 | $userId = $this->gEnv->getCurrentUserId(); // 現在のユーザ |
@@ -359,7 +360,16 @@ class blog_mainDb extends BaseDb | ||
359 | 360 | return false; |
360 | 361 | } |
361 | 362 | } |
362 | - | |
363 | + | |
364 | + // 記事画像の更新 | |
365 | + for ($i = 0; $i < count($images); $i++){ | |
366 | + $ret = $this->updateEntryImage($newSerial, $i, $images[$i]); | |
367 | + if (!$ret){ | |
368 | + $this->endTransaction(); | |
369 | + return false; | |
370 | + } | |
371 | + } | |
372 | + | |
363 | 373 | // トランザクション確定 |
364 | 374 | $ret = $this->endTransaction(); |
365 | 375 | return $ret; |
@@ -373,6 +383,7 @@ class blog_mainDb extends BaseDb | ||
373 | 383 | * @param string $html2 HTML(続き) |
374 | 384 | * @param int $status エントリー状態(0=未設定、1=編集中、2=公開、3=非公開) |
375 | 385 | * @param array $category カテゴリーID |
386 | + * @param array $images 記事画像 | |
376 | 387 | * @param string $blogId ブログID |
377 | 388 | * @param int $regUserId 投稿者ユーザID(0のときは更新しない) |
378 | 389 | * @param timestamp $regDt 投稿日時(空のときは更新しない) |
@@ -385,7 +396,7 @@ class blog_mainDb extends BaseDb | ||
385 | 396 | * @param array $otherParams その他のフィールド値 |
386 | 397 | * @return bool true = 成功、false = 失敗 |
387 | 398 | */ |
388 | - function updateEntryItem($serial, $name, $html, $html2, $status, $category, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial, | |
399 | + function updateEntryItem($serial, $name, $html, $html2, $status, $category, $images, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial, | |
389 | 400 | &$oldRecord, $otherParams = null) |
390 | 401 | { |
391 | 402 | $now = date("Y/m/d H:i:s"); // 現在日時 |
@@ -486,6 +497,15 @@ class blog_mainDb extends BaseDb | ||
486 | 497 | return false; |
487 | 498 | } |
488 | 499 | } |
500 | + | |
501 | + // 記事画像の更新 | |
502 | + for ($i = 0; $i < count($images); $i++){ | |
503 | + $ret = $this->updateEntryImage($newSerial, $i, $images[$i]); | |
504 | + if (!$ret){ | |
505 | + $this->endTransaction(); | |
506 | + return false; | |
507 | + } | |
508 | + } | |
489 | 509 | |
490 | 510 | // トランザクション確定 |
491 | 511 | $ret = $this->endTransaction(); |
@@ -602,6 +622,27 @@ class blog_mainDb extends BaseDb | ||
602 | 622 | return $ret; |
603 | 623 | } |
604 | 624 | /** |
625 | + * 記事画像の更新 | |
626 | + * | |
627 | + * @param int $serial 記事シリアル番号 | |
628 | + * @param int $index インデックス番号 | |
629 | + * @param string $path 画像パス | |
630 | + * @return bool true = 成功、false = 失敗 | |
631 | + */ | |
632 | + function updateEntryImage($serial, $index, $path) | |
633 | + { | |
634 | + // 新規レコード追加 | |
635 | + $queryStr = 'INSERT INTO blog_image '; | |
636 | + $queryStr .= '('; | |
637 | + $queryStr .= 'bm_entry_serial, '; | |
638 | + $queryStr .= 'bm_index, '; | |
639 | + $queryStr .= 'bm_image_src) '; | |
640 | + $queryStr .= 'VALUES '; | |
641 | + $queryStr .= '(?, ?, ?)'; | |
642 | + $ret =$this->execStatement($queryStr, array(intval($serial), $index, $path)); | |
643 | + return $ret; | |
644 | + } | |
645 | + /** | |
605 | 646 | * エントリー項目をシリアル番号で取得 |
606 | 647 | * |
607 | 648 | * @param string $serial シリアル番号 |