/** * @group String * @covers JString::transcode * @dataProvider transcodeData */ public function testTranscode($source, $from_encoding, $to_encoding, $expect) { $actual = JString::transcode($source, $from_encoding, $to_encoding); $this->assertEquals($expect, $actual); }
function formatPrice($price, $default = "") { if (!empty($price)) { //decode charset before using number_format $charset = 'UTF-8'; $decimal_separator = modJeaEmphasisNewestHelper::getComponentParam('decimals_separator', ','); $thousands_separator = modJeaEmphasisNewestHelper::getComponentParam('thousands_separator', ' '); $currency_symbol = modJeaEmphasisNewestHelper::getComponentParam('currency_symbol', '€'); $symbol_place = modJeaEmphasisNewestHelper::getComponentParam('symbol_place', 1); jimport('joomla.utilities.string'); if (function_exists('iconv')) { $decimal_separator = JString::transcode($decimal_separator, $charset, 'ISO-8859-1'); $thousands_separator = JString::transcode($thousands_separator, $charset, 'ISO-8859-1'); } else { $decimal_separator = utf8_decode($decimal_separator); $thousands_separator = utf8_decode($thousands_separator); } $price = number_format($price, 0, $decimal_separator, $thousands_separator); //re-encode if (function_exists('iconv')) { $price = JString::transcode($price, 'ISO-8859-1', $charset); } else { $price = utf8_encode($price); } //is currency symbol before or after price? if ($symbol_place == 1) { return htmlentities($price . ' ' . $currency_symbol, ENT_COMPAT, $charset); } else { return htmlentities($currency_symbol . ' ' . $price, ENT_COMPAT, $charset); } } else { return $default; } }
function _getUrlContent($url, $noImage = false, $isRaw = false) { JPlugin::loadLanguage('plg_activitycomment', JPATH_ADMINISTRATOR); CFactory::load('helpers', 'remote'); require_once JPATH_PLUGINS . DS . 'community' . DS . 'activitycomment' . DS . 'helper.php'; $params = ActivityComments::getParams(); $content = $this->connect($url); $image = ''; if ($content === false) { return false; } $allimages = array(); if (!$noImage) { // Look for facebook alike link style $reg = '/<link rel="image_src" href=*[\\"\']{0,1}([^\\"\'\\ >]*)/i'; preg_match($reg, $content, $matches); if (empty($matches)) { // BBC alike $reg = '/<meta name="THUMBNAIL_URL" content=*[\\"\']{0,1}([^\\"\'\\ >]*)/i'; preg_match($reg, $content, $matches); if (isset($matches[1])) { $allimages[] = $matches[1]; } } elseif (isset($matches[1])) { $allimages[] = $matches[1]; } $reg = '/<img.* src=*[\\"\']{0,1}([^\\"\'\\ >]*)/i'; preg_match_all($reg, $content, $matches); if (isset($matches[1])) { foreach ($matches[1] as $match) { $allimages[] = $match; } } $url = JString::str_ireplace('http://', '', $url); if (!empty($allimages)) { for ($i = 0; $i < count($allimages); $i++) { $img =& $allimages[$i]; if (JString::stristr($img, 'http://') === false) { $img = 'http://' . $url . '/' . ltrim($img, '/'); } } } } // get encoding type $reg = '/<meta http-equiv="[cC]ontent-[tT]ype" content="text\\/html;[ c]harset=*[\\"\']{0,1}([^\\"\\>]*)"/i'; preg_match($reg, $content, $matches); $charset = ''; if (isset($matches[1])) { $charset = $matches[1]; } $desc = ''; $image = $image; $info = ''; $title = ''; $reg = '/\\<meta name="description" content=*[\\"\']{0,1}([^\\"\\>]*)/i'; preg_match($reg, $content, $matches); if (isset($matches[1])) { $info .= '<div>' . $matches[1] . '</div>'; } else { $info = JText::_('NO INFO AVAILABLE'); } $reg = '/\\<title\\>(.*)\\<\\/title\\>/i'; preg_match($reg, $content, $matches); if (isset($matches[1])) { $title = '<div>' . $matches[1] . '</div>'; } else { $title = JText::_('NO TITLE ON SITE'); } $desc = '<table>'; $desc .= '<tr>'; if ($params->get('photopreview', 1)) { $desc .= '<td valign="top" width="25%">'; $maxW = 250; $maxH = 250; $width = 150; $height = 150; $sz = @getimagesize(html_entity_decode($image)); $totalimages = count($allimages); if (!empty($sz)) { $width = $sz[0] > $maxW ? $width : $sz[0]; $height = $sz[1] > $maxH ? $height : $sz[1]; } if (empty($allimages)) { $desc .= '<span>' . JText::_('NO IMAGE') . '</span>'; } else { $desc .= '<div id="images-wrapper">'; for ($ix = 0, $e = 1; $ix < count($allimages); $ix++, $e++) { $display = ' style="display: none;"'; if ($ix == 0) { $display = ' style="display: block;"'; } $image = $allimages[$ix]; $desc .= '<img src="' . $image . '" id="photo-share-' . $e . '" width="' . $width . '" height="' . $height . '"' . $display . ' />'; } $desc .= '<input type="hidden" id="photo-share-current" value="1" />'; $desc .= '<input type="hidden" id="photo-share-source" value="' . $allimages[0] . '" />'; $desc .= '</div>'; $desc .= '<div style="margin-top: 3px;">'; $desc .= '<a href="javascript:void(0);" onclick="prevPhoto(1);" id="prev-photo"><img src="' . JURI::root() . 'plugins/community/activitycomment/prev.png" border="0"/></a>'; $desc .= '<a href="javascript:void(0);" onclick="nextPhoto(\'' . $totalimages . '\');" id="next-photo"><img src="' . JURI::root() . 'plugins/community/activitycomment/next.png" border="0"/></a>'; $desc .= '</div>'; $desc .= '<div>'; $desc .= '<span id="image-count">1</span> ' . JText::_('OF') . ' <span id="total-count">' . $totalimages . '</span> ' . JText::_('IMAGES'); $desc .= '</div>'; } $desc .= '</td>'; } if ($charset) { $title = JString::transcode($title, $charset, 'UTF-8'); $info = JString::transcode($info, $charset, 'UTF-8'); } $desc .= '<td valign="top">'; $desc .= '<div style="font-weight:bold;">' . $title . '</div>'; $target = ' target="_blank"'; if ($params->get('shareurltarget', 1) == 0) { $target = ''; } $desc .= '<div style="color: #666;"><a href="http://' . $url . '"' . $target . '>http://' . $url . '</a></div>'; $desc .= '<div class="share-url-meta-info">' . $info . '</div>'; if (!$isRaw) { $desc .= '<input type="checkbox" name="no-image" id="no-image" /><label for="no-image" style="display: inline;">' . JText::_('NO THUMBNAIL') . '</label>'; } $desc .= '</td>'; $desc .= '</tr>'; $desc .= '</table>'; return $desc; }
/** * Format a number * * @param float|int $number * @param int $decimals * @return string */ function formatNumber($number = 0, $decimals = 0) { //verify if we need to represent decimal (ex : 2.00 = 2) $temp = intval($number); if ($temp - $number == 0.0) { $decimals = 0; } //decode charset before using number_format jimport('joomla.utilities.string'); if (function_exists('iconv')) { $decimal_separator = JString::transcode($this->params->get('decimals_separator', ','), $this->_charset, 'ISO-8859-1'); $thousands_separator = JString::transcode($this->params->get('thousands_separator', ' '), $this->_charset, 'ISO-8859-1'); } else { $decimal_separator = utf8_decode($this->params->get('decimals_separator', ',')); $thousands_separator = utf8_decode($this->params->get('thousands_separator', ' ')); } $number = number_format($number, $decimals, $decimal_separator, $thousands_separator); //re-encode if (function_exists('iconv')) { $number = JString::transcode($number, 'ISO-8859-1', $this->_charset); } else { $number = utf8_encode($number); } return $number; }