zishu's blog

zishu's blog

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

How does the Anghunk theme parse emojis in the backend comment list?

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

The solution was completed with the assistance of Dreaming Stars.

Introduction#

Anghunk comments carry many beautiful emojis, but under normal circumstances, the Typecho backend cannot parse these emojis correctly. As shown in the figure below;

image


However, after I parse the emojis, it can become like the one below. If you need this functionality in the theme, you can follow the steps I outline below for modification.

image

Modification#

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

/*
* 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 position where I placed it, it must be between <?php ... ?>

image

Find line 166, modify it, and replace the code in the tag with the one noted below.

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

After returning to the backend comment list, you will see that the comments have been successfully parsed. 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.