ELD
August 22nd, 2010, 02:59 PM
Hi all, apologies to start with i'm crap at explaining.
Basically i have an item bbcode which replaces a number with a thumbnail and info on that item:
function parse_items($text)
{
global $db;
$pattern = '#\([0-9]+)\[/item\]#mi';
preg_match_all($pattern, $text, $matches);
foreach ($matches[1] as $match)
{
$sql_item_match = "SELECT * FROM `items` WHERE `id` = {$match}";
$query_item_match = $db->query($sql_item_match);
$item_match = $db->fetch_assoc($query_item_match);
// lets see if we have a screenshot so we can use it's thumbnail shall we?
$sql_shot = "SELECT `image_filename` FROM `item_screenshots` WHERE `accepted` = 1 AND `item_id` = {$item_match['id']} LIMIT 1";
$query_shot = $db->query($sql_shot);
if ($db->num_rows($query_shot) == 1)
{
$shot = $db->fetch_assoc($query_shot);
$thumbnail = "<a href=\"uploads/images/{$shot['image_filename']}\" rel=\"lytebox\"><img src=\"uploads/images/thumbnails/{$shot['image_filename']}\" alt=\"\" /></a>";
}
else
{
$thumbnail = "<img src=\"images/noshot.jpg\" alt=\"\" />";
}
$replace = "<div class=\"item1\">
<a href=\"item.php?iid={$item_match['id']}\">{$item_match['name']}</a><br />
<span style=\"float: left; padding-right: 6px;\">{$thumbnail}</span>{$item_match['short_description']}<br />
Version: {$item_match['version']}
<br style=\"clear: both;\" />
</div>";
$text = preg_replace($pattern, $replace, $text);
}
return $text;
}
I am trying to now make an un-parser to turn the html that "12" makes back into that bbcode, but i can't seem to get it to work:
function undo_items($text)
{
// change quote html back to bbcode
$pattern = "#<div class=\"item1\">
<a href=\"item.php?iid=([0-9]+)\">(.*?)</a><br />
<span style=\"float: left; padding-right: 6px;\">(.*?)</span>(.*?)<br />
Version: (.*?)
<br style=\"clear: both;\" />
</div>#mix";
$replace = '[item]$1';
while(preg_match($pattern, $text))
{
$text = preg_replace($pattern, $replace, $text);
}
return $text;
}
I know theres probably something i'm overlooking as usual.
Basically i have an item bbcode which replaces a number with a thumbnail and info on that item:
function parse_items($text)
{
global $db;
$pattern = '#\([0-9]+)\[/item\]#mi';
preg_match_all($pattern, $text, $matches);
foreach ($matches[1] as $match)
{
$sql_item_match = "SELECT * FROM `items` WHERE `id` = {$match}";
$query_item_match = $db->query($sql_item_match);
$item_match = $db->fetch_assoc($query_item_match);
// lets see if we have a screenshot so we can use it's thumbnail shall we?
$sql_shot = "SELECT `image_filename` FROM `item_screenshots` WHERE `accepted` = 1 AND `item_id` = {$item_match['id']} LIMIT 1";
$query_shot = $db->query($sql_shot);
if ($db->num_rows($query_shot) == 1)
{
$shot = $db->fetch_assoc($query_shot);
$thumbnail = "<a href=\"uploads/images/{$shot['image_filename']}\" rel=\"lytebox\"><img src=\"uploads/images/thumbnails/{$shot['image_filename']}\" alt=\"\" /></a>";
}
else
{
$thumbnail = "<img src=\"images/noshot.jpg\" alt=\"\" />";
}
$replace = "<div class=\"item1\">
<a href=\"item.php?iid={$item_match['id']}\">{$item_match['name']}</a><br />
<span style=\"float: left; padding-right: 6px;\">{$thumbnail}</span>{$item_match['short_description']}<br />
Version: {$item_match['version']}
<br style=\"clear: both;\" />
</div>";
$text = preg_replace($pattern, $replace, $text);
}
return $text;
}
I am trying to now make an un-parser to turn the html that "12" makes back into that bbcode, but i can't seem to get it to work:
function undo_items($text)
{
// change quote html back to bbcode
$pattern = "#<div class=\"item1\">
<a href=\"item.php?iid=([0-9]+)\">(.*?)</a><br />
<span style=\"float: left; padding-right: 6px;\">(.*?)</span>(.*?)<br />
Version: (.*?)
<br style=\"clear: both;\" />
</div>#mix";
$replace = '[item]$1';
while(preg_match($pattern, $text))
{
$text = preg_replace($pattern, $replace, $text);
}
return $text;
}
I know theres probably something i'm overlooking as usual.