• R/O
  • HTTP
  • SSH
  • HTTPS

magic3: Commit

Cloud computing platform


Commit MetaInfo

Revisiónb9b00dd8d34ec9a6df7c3b6d54eeb20f9fbb09b1 (tree)
Tiempo2019-02-28 08:32:40
Autornaoki hirata <naoki@magi...>
Commiternaoki hirata

Log Message

ブログ記事から画像ギャラリー用に画像を抜き出す処理を追加。

Cambiar Resumen

Diferencia incremental

--- a/include/manager/imageManager.php
+++ b/include/manager/imageManager.php
@@ -8,7 +8,7 @@
88 *
99 * @package Magic3 Framework
1010 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11- * @copyright Copyright 2006-2015 Magic3 Project.
11+ * @copyright Copyright 2006-2019 Magic3 Project.
1212 * @license http://www.gnu.org/copyleft/gpl.html GPL License
1313 * @version SVN: $Id$
1414 * @link http://www.magic3.org
@@ -33,6 +33,8 @@ class ImageManager extends Core
3333 const PARSE_IMAGE_FORMAT = '/(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマット解析用
3434 // const PARSE_IMAGE_FORMAT_TYPE = '/(.*?)\s*=\s*(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用
3535 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+
3638 // DB定義値
3739 // const CF_SITE_LOGO_FILENAME = 'site_logo_filename'; // サイトロゴファイル
3840 const CF_SITE_LOGO_FORMAT = 'site_logo_format'; // サイトロゴフォーマット
@@ -98,7 +100,6 @@ class ImageManager extends Core
98100
99101 for ($i = 0; $i < count($formatArray); $i++){
100102 $format = trim($formatArray[$i]);
101-// $ret = preg_match('/(\d+)(.*)\.(gif|png|jpg|jpeg|bmp)$/i', $format, $matches);
102103 $ret = $this->parseImageFormat($format, $imageType, $imageAttr, $imageSize, $imageWidthHeight);
103104 if ($ret){
104105 $thumbSize = $imageWidthHeight;
@@ -791,8 +792,7 @@ class ImageManager extends Core
791792 {
792793 global $gEnvManager;
793794
794- $exp = '/<img[^<]*?src\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
795- $ret = preg_match($exp, $html, $matches);
795+ $ret = preg_match(self::PARSE_IMAGE_TAG, $html, $matches);
796796 if ($ret){
797797 $path = $gEnvManager->getMacroPath($matches[1]); // 画像URL
798798 $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
801801 return '';
802802 }
803803 /**
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+ /**
804823 * サイトロゴ画像のURLを取得
805824 *
806825 * @param string $type 画像タイプ「sm」「md」「lg」。空の場合はロゴ格納ディレクトリURLを返す。
@@ -1214,7 +1233,6 @@ class ImageManager extends Core
12141233 function parseImageFormat($format, &$imageType, &$imageAttr, &$imageSize, &$imageWidthHeight = null)
12151234 {
12161235 $format = trim($format);
1217- //$ret = preg_match('/(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i', $format, $matches); // 「MMxNNc.jpg」タイプのフォーマットを解析
12181236 $ret = preg_match(self::PARSE_IMAGE_FORMAT, $format, $matches); // 「MMxNNc.jpg」タイプのフォーマットを解析
12191237 if ($ret){
12201238 $imageSize = $matches[1];
@@ -1262,8 +1280,6 @@ class ImageManager extends Core
12621280 for ($i = 0; $i < count($lines); $i++){
12631281 $line = trim($lines[$i]);
12641282 if (!empty($line)){
1265- //$ret = preg_match(, $line, $matches);
1266- //'/(.*?)\s*=\s*(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用
12671283 $ret = preg_match(self::PARSE_IMAGE_FORMAT_TYPE, $line, $matches);
12681284 if ($ret){
12691285 $imageType = $matches[1];
--- a/include/sql/update/2018110501_to_2019022701.sql
+++ b/include/sql/update/2018110501_to_2019022701.sql
@@ -20,8 +20,8 @@
2020
2121 -- *** システム標準テーブル ***
2222 -- ブログ記事画像マスター
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 (
2525 bm_serial INT AUTO_INCREMENT, -- レコードシリアル番号
2626 bm_entry_serial INT DEFAULT 0 NOT NULL, -- ブログ記事シリアル番号
2727 bm_index INT DEFAULT 0 NOT NULL, -- インデックス番号
--- a/widgets/blog_main/include/container/admin_blog_mainEntryWidgetContainer.php
+++ b/widgets/blog_main/include/container/admin_blog_mainEntryWidgetContainer.php
@@ -488,6 +488,11 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta
488488 $html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
489489 $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
490490
491+ // 記事に含まれるすべての画像のパスを取得
492+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
493+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
494+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
495+
491496 // 追加パラメータ
492497 $otherParams = array( 'be_description' => $desc, // 簡易説明
493498 'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
@@ -499,10 +504,10 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta
499504
500505 // 記事データを追加
501506 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,
503508 $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
504509 } 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,
506511 $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
507512 }
508513 if ($ret){
@@ -621,6 +626,11 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta
621626 $html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
622627 $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
623628
629+ // 記事に含まれるすべての画像のパスを取得
630+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
631+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
632+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
633+
624634 // 追加パラメータ
625635 $otherParams = array( 'be_description' => $desc, // 簡易説明
626636 'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
@@ -639,7 +649,7 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta
639649 }
640650
641651 // 記事データを更新
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,
643653 ''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams);
644654 /* if ($ret){
645655 // コンテンツに画像がなくなった場合は、サムネールを削除
--- a/widgets/blog_main/include/container/blog_mainEntryWidgetContainer.php
+++ b/widgets/blog_main/include/container/blog_mainEntryWidgetContainer.php
@@ -490,6 +490,11 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer
490490 $html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
491491 $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
492492
493+ // 記事に含まれるすべての画像のパスを取得
494+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
495+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
496+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
497+
493498 // 追加パラメータ
494499 $otherParams = array( 'be_description' => $desc, // 簡易説明
495500 'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
@@ -501,10 +506,10 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer
501506
502507 // 記事データを追加
503508 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,
505510 $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
506511 } 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,
508513 $this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
509514 }
510515 if ($ret){
@@ -623,6 +628,11 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer
623628 $html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
624629 $html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
625630
631+ // 記事に含まれるすべての画像のパスを取得
632+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
633+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
634+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
635+
626636 // 追加パラメータ
627637 $otherParams = array( 'be_description' => $desc, // 簡易説明
628638 'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
@@ -641,7 +651,7 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer
641651 }
642652
643653 // 記事データを更新
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,
645655 ''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams);
646656 /* if ($ret){
647657 // コンテンツに画像がなくなった場合は、サムネールを削除
--- a/widgets/blog_main/include/db/blog_mainDb.php
+++ b/widgets/blog_main/include/db/blog_mainDb.php
@@ -8,7 +8,7 @@
88 *
99 * @package Magic3 Framework
1010 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11- * @copyright Copyright 2006-2017 Magic3 Project.
11+ * @copyright Copyright 2006-2019 Magic3 Project.
1212 * @license http://www.gnu.org/copyleft/gpl.html GPL License
1313 * @version SVN: $Id$
1414 * @link http://www.magic3.org
@@ -251,6 +251,7 @@ class blog_mainDb extends BaseDb
251251 * @param string $html2 HTML(続き)
252252 * @param int $status エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
253253 * @param array $category カテゴリーID
254+ * @param array $images 記事画像
254255 * @param string $blogId ブログID
255256 * @param int $regUserId 投稿者ユーザID
256257 * @param timestamp $regDt 投稿日時
@@ -262,7 +263,7 @@ class blog_mainDb extends BaseDb
262263 * @param array $otherParams その他のフィールド値
263264 * @return bool true = 成功、false = 失敗
264265 */
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)
266267 {
267268 $now = date("Y/m/d H:i:s"); // 現在日時
268269 $userId = $this->gEnv->getCurrentUserId(); // 現在のユーザ
@@ -359,7 +360,16 @@ class blog_mainDb extends BaseDb
359360 return false;
360361 }
361362 }
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+
363373 // トランザクション確定
364374 $ret = $this->endTransaction();
365375 return $ret;
@@ -373,6 +383,7 @@ class blog_mainDb extends BaseDb
373383 * @param string $html2 HTML(続き)
374384 * @param int $status エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
375385 * @param array $category カテゴリーID
386+ * @param array $images 記事画像
376387 * @param string $blogId ブログID
377388 * @param int $regUserId 投稿者ユーザID(0のときは更新しない)
378389 * @param timestamp $regDt 投稿日時(空のときは更新しない)
@@ -385,7 +396,7 @@ class blog_mainDb extends BaseDb
385396 * @param array $otherParams その他のフィールド値
386397 * @return bool true = 成功、false = 失敗
387398 */
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,
389400 &$oldRecord, $otherParams = null)
390401 {
391402 $now = date("Y/m/d H:i:s"); // 現在日時
@@ -486,6 +497,15 @@ class blog_mainDb extends BaseDb
486497 return false;
487498 }
488499 }
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+ }
489509
490510 // トランザクション確定
491511 $ret = $this->endTransaction();
@@ -602,6 +622,27 @@ class blog_mainDb extends BaseDb
602622 return $ret;
603623 }
604624 /**
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+ /**
605646 * エントリー項目をシリアル番号で取得
606647 *
607648 * @param string $serial シリアル番号
Show on old repository browser