Commit 7c13cdc9 by halweg

fix 富文本编解码

parent f21db3e9
...@@ -149,12 +149,27 @@ class MediaFeed extends Template { ...@@ -149,12 +149,27 @@ class MediaFeed extends Template {
public function getMedia() { public function getMedia() {
$cache = $this->getMediaByCache(); $cache = $this->getMediaByCache();
if (!empty($cache)) { if (!empty($cache)) {
return $cache; return $this->encodePostContent($cache);
} }
$feed = $this->getMediaByApi(); $feed = $this->getMediaByApi();
if (isset($feed['data'])) { if (isset($feed['data'])) {
$this->cacheFeed($this->_json->serialize($feed)); $this->cacheFeed($this->_json->serialize($feed));
} else {
return [];
}
return $this->encodePostContent($feed);
}
public function encodePostContent($feed)
{
foreach ($feed['data'] as $index => $row) {
if (isset($row['caption'])) {
$feed['data'][$index]["caption"] = base64_encode($row["caption"]);
}
} }
$feed['data'] = array_merge($feed['data'], []);
return $feed; return $feed;
} }
} }
\ No newline at end of file
...@@ -270,15 +270,17 @@ $media = $block->getMedia()['data']; ...@@ -270,15 +270,17 @@ $media = $block->getMedia()['data'];
<script> <script>
require([ require([
'jquery', 'ko', 'mage/translate' 'jquery', 'ko', 'mage/translate'
], function ($, ko) { ], function ($, ko, _) {
$("#instagram-modal-close").on('click', function () { $("#instagram-modal-close").on('click', function () {
$("#instagram-modal").hide() $("#instagram-modal").hide()
}); });
$(".instagram-media-wrapper").on('click', function () { $(".instagram-media-wrapper").on('click', function () {
let data = $(this).data("feed-data"); let data = $(this).data("feed-data");
console.log(data);
let link = data.permalink; let link = data.permalink;
let content = data.caption; let content = '';
if (data.hasOwnProperty('caption')) {
content = decodeURIComponent(escape(atob(data.caption)));
}
let media = data.media_url; let media = data.media_url;
let date = data.timestamp; let date = data.timestamp;
let type = data.media_type; let type = data.media_type;
...@@ -296,5 +298,6 @@ $media = $block->getMedia()['data']; ...@@ -296,5 +298,6 @@ $media = $block->getMedia()['data'];
$("#instagram-caption").html("").html(content); $("#instagram-caption").html("").html(content);
$("#instagram-modal").show() $("#instagram-modal").show()
}); });
}); });
</script> </script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment