/** * Wrap in A tag links in HTML string, which aren't wrapped in A tag yet * @param $sHtmlOrig - HTML string * @param $sAttrs - attributes string to add to the added A tag * @return modified HTML string, in case of errror original string is returned */ function bx_linkify_html($sHtmlOrig, $sAttrs = '') { if (!trim($sHtmlOrig)) { return $sHtmlOrig; } $sId = 'bx-linkify-' . md5(microtime()); $dom = new DOMDocument(); @$dom->loadHTML('<?xml encoding="UTF-8"><div id="' . $sId . '">' . $sHtmlOrig . '</div>'); $xpath = new DOMXpath($dom); foreach ($xpath->query('//text()') as $text) { $frag = $dom->createDocumentFragment(); $frag->appendXML(bx_linkify($text->nodeValue, $sAttrs, true)); $text->parentNode->replaceChild($frag, $text); } if (version_compare(PHP_VERSION, '5.3.6') >= 0) { $s = $dom->saveHTML($dom->getElementById($sId)); } else { $s = $dom->saveXML($dom->getElementById($sId), LIBXML_NOEMPTYTAG); } if (false === $s) { // in case of error return original string return $sHtmlOrig; } if (false !== ($iPos = mb_strpos($s, '<html><body>')) && $iPos < mb_strpos($s, $sId)) { $s = mb_substr($s, $iPos + 12, -15); } // strip <html><body> tags and everything before them return mb_substr($s, 54, -6); // strip added tags }
function getAlbumInfo(&$aInfo) { $aForm = array('form_attrs' => array('id' => $this->_oConfig->getMainPrefix() . '_album_view_form'), 'params' => array('remove_form' => true), 'inputs' => array('location' => array('type' => 'value', 'value' => bx_linkify(process_text_output($aInfo['Location'])), 'caption' => _t('_Location')), 'description' => array('type' => 'value', 'value' => bx_linkify(process_html_output($aInfo['Description'])), 'caption' => _t('_Description')), 'date' => array('type' => 'value', 'value' => getLocaleDate($aInfo['Date'], BX_DOL_LOCALE_DATE_SHORT) . ' (' . defineTimeInterval($aInfo['Date'], false) . ')', 'caption' => _t('_Date')))); $aForm['inputs'] = array_filter($aForm['inputs'], function ($aInput) { return !!$aInput['value']; }); $oForm = new BxTemplFormView($aForm); return array($oForm->getCode(), array(), array(), false); }