zishu's blog

zishu's blog

一个热爱生活的博主。https://zishu.me

How to parse emojis in the background comment list in Anghunk theme?

This article is specifically written for the Anghunk theme development documentation.
https://github.com/98fuel/Anghunk

The solution was completed with the assistance of Mengfanxing.

Introduction#

Anghunk comments come with many beautiful emojis, but normally Typecho backend cannot parse these emojis correctly. As shown in the image below;

image


However, after parsing the emojis, it can be displayed as shown below. If the theme requires this functionality, you can follow the steps below to modify it.

image

Modification#

Open the /admin/manage-comments.php file and insert the following code at the beginning:

/*
* Parse emojis
*/
function getparseBiaoQingComment($content) {
	$emopath=$_SERVER['REQUEST_SCHEME'].":". DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR . $_SERVER['HTTP_HOST'];
	$emo = false;
	global $emo;
	if(!$emo) {
		$emo = json_decode(file_get_contents(dirname(dirname(dirname(__FILE__))).'/zburu.com/usr/themes/Anghunk/libs/OwO.json'), true);
	}
	foreach ($emo as $v) {
		if($v['type'] == 'image') {
			foreach ($v['container'] as $vv) {
				$emoaa="::".$v['name'].":".$vv['icon']."::";
				$content = str_replace($emoaa, '  <img style="max-height:40px;vertical-align:middle;" src="'.$emopath.'/usr/themes/Anghunk/libs/emotion/'.$v['name'].'/'.$vv['icon'] .'.png"  alt="'.$vv['text'] .'">  ', $content);
			}
		}
	}
	return $content;
}

Note the placement, it must be between <?php ... ?>

**Find line 166, and modify it by replacing the code inside the tag with the code below. **

<div class="comment-content">
   <!-- Parse and output comments with emojis -->
   <?php $con=$comments->content; echo getparseBiaoQingComment($con); ?>
</div> 

Afterwards, you can see that the comments are successfully parsed in the backend comment list. This method is only applicable to the Anghunk theme.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.