*
* @package Magic3 Framework
* @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright Copyright 2006-2015 Magic3 Project.
+ * @copyright Copyright 2006-2019 Magic3 Project.
* @license http://www.gnu.org/copyleft/gpl.html GPL License
* @version SVN: $Id$
* @link http://www.magic3.org
const PARSE_IMAGE_FORMAT = '/(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマット解析用
// const PARSE_IMAGE_FORMAT_TYPE = '/(.*?)\s*=\s*(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用
const PARSE_IMAGE_FORMAT_TYPE = '/(.*?)\s*=\s*(\d+)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用
+ const PARSE_IMAGE_TAG = '/<img[^<]*?src\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si'; // HTMLからIMGタグ取得用
+
// DB定義値
// const CF_SITE_LOGO_FILENAME = 'site_logo_filename'; // サイトロゴファイル
const CF_SITE_LOGO_FORMAT = 'site_logo_format'; // サイトロゴフォーマット
for ($i = 0; $i < count($formatArray); $i++){
$format = trim($formatArray[$i]);
-// $ret = preg_match('/(\d+)(.*)\.(gif|png|jpg|jpeg|bmp)$/i', $format, $matches);
$ret = $this->parseImageFormat($format, $imageType, $imageAttr, $imageSize, $imageWidthHeight);
if ($ret){
$thumbSize = $imageWidthHeight;
{
global $gEnvManager;
- $exp = '/<img[^<]*?src\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
- $ret = preg_match($exp, $html, $matches);
+ $ret = preg_match(self::PARSE_IMAGE_TAG, $html, $matches);
if ($ret){
$path = $gEnvManager->getMacroPath($matches[1]); // 画像URL
$path = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $gEnvManager->getSystemRootPath(), $path);// マクロ変換
return '';
}
/**
+ * コンテンツからサイト内のすべての画像のパスを取得
+ *
+ * @param string $html 検索コンテンツ(画像パスはマクロ変換済み)
+ * @return array 画像パス(リソースディレクトリからの相対パス)
+ */
+ function getSiteImagePath($html)
+ {
+ $imagePaths = array();
+ preg_match_all(self::PARSE_IMAGE_TAG, $html, $matches, PREG_SET_ORDER);
+ for ($i = 0; $i < count($matches); $i++){
+ $path = $matches[$i][1];
+ if (strStartsWith($path, M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_DIR_NAME_RESOURCE)){
+ $path = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_DIR_NAME_RESOURCE, '', $path);
+ if (!in_array($path, $imagePaths)) $imagePaths[] = $path;
+ }
+ }
+ return $imagePaths;
+ }
+ /**
* サイトロゴ画像のURLを取得
*
* @param string $type 画像タイプ「sm」「md」「lg」。空の場合はロゴ格納ディレクトリURLを返す。
function parseImageFormat($format, &$imageType, &$imageAttr, &$imageSize, &$imageWidthHeight = null)
{
$format = trim($format);
- //$ret = preg_match('/(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i', $format, $matches); // 「MMxNNc.jpg」タイプのフォーマットを解析
$ret = preg_match(self::PARSE_IMAGE_FORMAT, $format, $matches); // 「MMxNNc.jpg」タイプのフォーマットを解析
if ($ret){
$imageSize = $matches[1];
for ($i = 0; $i < count($lines); $i++){
$line = trim($lines[$i]);
if (!empty($line)){
- //$ret = preg_match(, $line, $matches);
- //'/(.*?)\s*=\s*(\d+)([xX]?)(\d*)(.*)\.(gif|png|jpg|jpeg|bmp)$/i'; // 画像フォーマットタイプ解析用
$ret = preg_match(self::PARSE_IMAGE_FORMAT_TYPE, $line, $matches);
if ($ret){
$imageType = $matches[1];
-- *** システム標準テーブル ***
-- ブログ記事画像マスター
-DROP TABLE IF EXISTS blog_entry_image;
-CREATE TABLE blog_entry_image (
+DROP TABLE IF EXISTS blog_image;
+CREATE TABLE blog_image (
bm_serial INT AUTO_INCREMENT, -- レコードシリアル番号
bm_entry_serial INT DEFAULT 0 NOT NULL, -- ブログ記事シリアル番号
bm_index INT DEFAULT 0 NOT NULL, -- インデックス番号
$html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
$html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
+ // 記事に含まれるすべての画像のパスを取得
+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
+
// 追加パラメータ
$otherParams = array( 'be_description' => $desc, // 簡易説明
'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
// 記事データを追加
if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // 多言語でデフォルト言語、または単一言語のとき
- $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
+ $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId,
$this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
} else {
- $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
+ $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId,
$this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
}
if ($ret){
$html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
$html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
+ // 記事に含まれるすべての画像のパスを取得
+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
+
// 追加パラメータ
$otherParams = array( 'be_description' => $desc, // 簡易説明
'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
}
// 記事データを更新
- $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
+ $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId,
''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams);
/* if ($ret){
// コンテンツに画像がなくなった場合は、サムネールを削除
$html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
$html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
+ // 記事に含まれるすべての画像のパスを取得
+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
+
// 追加パラメータ
$otherParams = array( 'be_description' => $desc, // 簡易説明
'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
// 記事データを追加
if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // 多言語でデフォルト言語、または単一言語のとき
- $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
+ $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId,
$this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
} else {
- $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
+ $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId,
$this->_userId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
}
if ($ret){
$html = $this->gInstance->getTextConvManager()->convToContentMacro($html);
$html2 = $this->gInstance->getTextConvManager()->convToContentMacro($html2);
+ // 記事に含まれるすべての画像のパスを取得
+ $imagePathArray = $this->gInstance->getImageManager()->getSiteImagePath($html);
+ $imagePathArray2 = $this->gInstance->getImageManager()->getSiteImagePath($html2);
+ $imagePathArray = array_unique(array_merge($imagePathArray, $imagePathArray2));
+
// 追加パラメータ
$otherParams = array( 'be_description' => $desc, // 簡易説明
'be_meta_description' => $metaDesc, // ページ要約(METAタグ)
}
// 記事データを更新
- $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
+ $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $imagePathArray, $this->blogId,
''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams);
/* if ($ret){
// コンテンツに画像がなくなった場合は、サムネールを削除
*
* @package Magic3 Framework
* @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright Copyright 2006-2017 Magic3 Project.
+ * @copyright Copyright 2006-2019 Magic3 Project.
* @license http://www.gnu.org/copyleft/gpl.html GPL License
* @version SVN: $Id$
* @link http://www.magic3.org
* @param string $html2 HTML(続き)
* @param int $status エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
* @param array $category カテゴリーID
+ * @param array $images 記事画像
* @param string $blogId ブログID
* @param int $regUserId 投稿者ユーザID
* @param timestamp $regDt 投稿日時
* @param array $otherParams その他のフィールド値
* @return bool true = 成功、false = 失敗
*/
- function addEntryItem($id, $langId, $name, $html, $html2, $status, $category, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial, $otherParams = null)
+ function addEntryItem($id, $langId, $name, $html, $html2, $status, $category, $images, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial, $otherParams = null)
{
$now = date("Y/m/d H:i:s"); // 現在日時
$userId = $this->gEnv->getCurrentUserId(); // 現在のユーザ
return false;
}
}
-
+
+ // 記事画像の更新
+ for ($i = 0; $i < count($images); $i++){
+ $ret = $this->updateEntryImage($newSerial, $i, $images[$i]);
+ if (!$ret){
+ $this->endTransaction();
+ return false;
+ }
+ }
+
// トランザクション確定
$ret = $this->endTransaction();
return $ret;
* @param string $html2 HTML(続き)
* @param int $status エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
* @param array $category カテゴリーID
+ * @param array $images 記事画像
* @param string $blogId ブログID
* @param int $regUserId 投稿者ユーザID(0のときは更新しない)
* @param timestamp $regDt 投稿日時(空のときは更新しない)
* @param array $otherParams その他のフィールド値
* @return bool true = 成功、false = 失敗
*/
- function updateEntryItem($serial, $name, $html, $html2, $status, $category, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial,
+ function updateEntryItem($serial, $name, $html, $html2, $status, $category, $images, $blogId, $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, &$newSerial,
&$oldRecord, $otherParams = null)
{
$now = date("Y/m/d H:i:s"); // 現在日時
return false;
}
}
+
+ // 記事画像の更新
+ for ($i = 0; $i < count($images); $i++){
+ $ret = $this->updateEntryImage($newSerial, $i, $images[$i]);
+ if (!$ret){
+ $this->endTransaction();
+ return false;
+ }
+ }
// トランザクション確定
$ret = $this->endTransaction();
return $ret;
}
/**
+ * 記事画像の更新
+ *
+ * @param int $serial 記事シリアル番号
+ * @param int $index インデックス番号
+ * @param string $path 画像パス
+ * @return bool true = 成功、false = 失敗
+ */
+ function updateEntryImage($serial, $index, $path)
+ {
+ // 新規レコード追加
+ $queryStr = 'INSERT INTO blog_image ';
+ $queryStr .= '(';
+ $queryStr .= 'bm_entry_serial, ';
+ $queryStr .= 'bm_index, ';
+ $queryStr .= 'bm_image_src) ';
+ $queryStr .= 'VALUES ';
+ $queryStr .= '(?, ?, ?)';
+ $ret =$this->execStatement($queryStr, array(intval($serial), $index, $path));
+ return $ret;
+ }
+ /**
* エントリー項目をシリアル番号で取得
*
* @param string $serial シリアル番号