I've created a custom block, and I'm trying to get this custom block to output a specific piece of HTML. The HTML needs to be different on every page, because it needs to include the page's URL in it. For instance, if the page is http://www.businesskorea.co.kr/article/7789/content-business-marginalized-samsung-reorganizes-media-solution-center-owing-poor, then the block should output:
<img src="http://cp.news.search.daum.net/api/publish.json?nurl={http%3A%2F%2Fwww.businesskorea.co.kr%2Farticle%2F7789%2Fcontent-business-marginalized-samsung-reorganizes-media-solution-center-owing-poor}&xml_url={http%3A%2F%2Fwww.businesskorea.co.kr%2Farticle%2F7789%2Fcontent-business-marginalized-samsung-reorganizes-media-solution-center-owing-poor%3Fformat%3Dxml}&channel=business" style="display:none;">
This is to be compatible with daum.net's news publishing functionality. The code that I've written up for this custom block looks like this:
<?php
/**
* Implements hook_block_info().
*/
function bkcustom_block_info() {
$blocks = array();
$blocks['bkcustom_daum_json_block'] = array(
'info' => t('BKCustom Daum JSON'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function bkcustom_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'bkcustom_daum_json_block':
$block['subject'] = '';
$block['content'] = BKCUSTOM_DAUM_JSON_BLOCK_CONTENT();
break;
}
return $block;
}
function BKCUSTOM_DAUM_JSON_BLOCK_CONTENT() {
$path_alias = drupal_get_path_alias($_GET["q"]);
$encoded_path_alias = urlencode($path_alias);
$output = t("<img src=\"http://cp.news.search.daum.net/api/publish.json?nurl={http%3A%2F%2Fwww.businesskorea.co.kr%2F" . $encoded_path_alias . "}&xml_url={http%3A%2F%2Fwww.businesskorea.co.kr%2F" . $encoded_path_alias . "%3Fformat%3Dxml}&channel=business\" style=\"display:none;\" />");
return $output;
}
Which outputs almost, but not quite, what I need. The output changes ampersands to &
, and somehow deletes the final forward slash (/) at the end of the IMG tag. The output looks like this:
<img src="http://cp.news.search.daum.net/api/publish.json?nurl={http%3A%2F%2Fwww.businesskorea.co.kr%2Farticle%2F7789%2Fcontent-business-marginalized-samsung-reorganizes-media-solution-center-owing-poor}&xml_url={http%3A%2F%2Fwww.businesskorea.co.kr%2Farticle%2F7789%2Fcontent-business-marginalized-samsung-reorganizes-media-solution-center-owing-poor%3Fformat%3Dxml}&channel=business" style="display:none;">
The most frustrating part of this exercise is that if I delete the opening and closing brackets, <>, the code works perfectly and prints out each character exactly as I need it to. That's how I tested to see if it would work. But when I introduce opening and closing brackets, the code changes and the JSON query or whatever the crap this is fails.
How can I preserve the & and / characters?