Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-06-17 12:11:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Emojify your site content

Although not strictly related to plugin development — it’s more a journey on how to do it — the ability to add Emoji characters to your posts or user comments is something that smd_wrap can help with.

I don’t know of an official plugin and initially looked at an7_filter, but it wasn’t quite man enough for the job without modification. So here’s how to roll your own Emojified site content:

  1. Obtain an Emoji font. I chose emojisymbols.com because of its permissive licence.
  2. Extract the files in the zip file, and upload EmojiSymbols-Regular.woff to your site in a suitable location (here we’ll use a /font directory off your site root).
  3. Add the following to your Page template’s <head>:
<txp:if_section name="some, sections, here">
<style>
/*
EmojiSymbols Font (c)blockworks - Kenichi Kaneko
http://emojisymbols.com/
*/
@font-face {
	font-family: "EmojiSymbols";
	src: url('/font/EmojiSymbols-Regular.woff') format('woff');
	text-decoration: none;
	font-style: normal;
}
</style>
</txp:if_section>
  1. Install and activate smd_wrap. You may be able to use pax_grep as a lighter alternative, but I haven’t tried it (not sure if it handles capturing parentheses with replacements).
  2. Create a new Miscellaneous Form called emojify and paste in this scary-looking content:
<txp:smd_wrap
   transform="replace|regex|/&amp;#x([\da-zA-Z]{4,5});/|&#x${1};"
   delim="~"><txp:yield /></txp:smd_wrap>
  1. Go through your Pages / Forms and wrap <txp:output_form form="emojify"> around any content in which you want to permit Emoji characters, e.g. <txp:output_form form="emojify"><txp:comment_message /></txp:output_form>.
  2. Profit.

All smd_wrap does in this instance is remove the encoded &amp; character and replaces it with a vanilla & symbol on anything that looks like an HTML Emoji-like character sequence. You could tighten the regex if you prefer to only pick up a dedicated subset of the characters. Right now it might pick up quotes (&#8220; and &#8221;), for example.

The upshot is that anybody putting &#x1F34C; in their comment will see a Minion’s favourite food appear in its place when submitted. You may like to wrap the emojify form around <txp:comment_preview /> too so the symbols appear in the preview area. See it in action here.

It might not appeal to the people who prefer to use a WYSIWYG toolbar to insert them, but for typey folk like me it’s good enough. Any improvements to the technique or other character sets you like, please feel free to post them here.

Hope it helps.

Last edited by Bloke (2015-06-17 13:44:00)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

#2 2015-06-17 13:13:50

candyman
Member
From: Italy
Registered: 2006-08-08
Posts: 684

Re: Emojify your site content

Love the

Emoji sentence => Intended meaning => Possible misinterpretation

table! lol :D

BTW, have you recently changed your website font? What is that? Very clear to read.

Offline

#3 2015-06-17 13:37:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

Re: Emojify your site content

candyman wrote #291603:

Love the… Possible misinterpretation table!

Hehe, thanks. Had fun putting that together.

have you recently changed your website font? What is that? Very clear to read.

It’s ABeeZee which is a children’s learning font, but it appealed to me because it remained super-readable at lots of different screen resolutions and sizes. And I’m just a big kid at heart.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

Board footer

Powered by FluxBB