Created
August 30, 2013 10:25
-
-
Save roboter/6388479 to your computer and use it in GitHub Desktop.
Wordpress plugin to change <lj user="username"> to html in blogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Livejournal User | |
Plugin URI: http://www.begemotik.ee/LivejournalUserPlugin/ | |
Description: This plugin replaces <lj user="username"> with the correct html code. | |
Author: Aleksei Prokopov. | |
Version: 0.1 | |
Author URI: http://www.begemotik.ee/ | |
*/ | |
function parse($content) | |
{ | |
$i = 0; | |
while ($i == 0) | |
{ | |
$user = explode('<lj user="', $content); | |
$user = explode('">', $user[1]); | |
$user = $user[0]; | |
$old_string = '<lj user="'.$user.'">'; | |
$new_string = | |
'<span class="ljuser" lj:user="'.$user.'">'. | |
'<a href="http://'.$user.'.livejournal.com/profile">'. | |
'<img alt="[info]" height="17" src="http://p-stat.livejournal.com/img/userinfo.gif" '. | |
'style="vertical-align: bottom; border: 0; padding-right: 1px;" width="17"'. | |
'/></a>'. | |
'<a href="http://'.$user.'.livejournal.com/"><b>'.$user.'</b>'. | |
'</a></span>'; | |
$content = str_replace($old_string, $new_string, $content); | |
if ($user == '') break; | |
} | |
$i = 0; | |
while ($i == 0) | |
{ | |
$comm = explode('<lj comm="', $content); | |
$comm = explode('">', $comm[1]); | |
$comm = $comm[0]; | |
$old_string = '<lj comm="'.$comm.'">'; | |
'<span class="ljuser" lj:user="'.$comm.'" style="white-space: nowrap;">'. | |
'<a href="http://community.livejournal.com/'.$comm.'/profile">'. | |
'<img alt="[info]" height="16" src="http://p-stat.livejournal.com/img/community.gif" '. | |
'style="vertical-align: bottom; border: 0; padding-right: 1px;" width="16" /></a><a'. | |
' href="http://community.livejournal.com/'.$comm.'/"><b>'.$comm.'</b></a></span>'; | |
$content = str_replace($old_string, $new_string, $content); | |
if ($comm == '') break; | |
} | |
return $content; | |
} | |
add_filter('the_content', 'parse'); | |
add_filter('the_title', 'parse'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment