/** * Convert content to HTML * * @param string $context The context of the content being passed to the plugin. * @param object $article The article object. Note $article->text is also available * @param object $params The article params * @param int $page The 'page' number */ public function onContentPrepare($context, &$article, &$params, $page = 0) { //if (!($article instanceof \Hubzero\Base\Object) || $context == 'com_content.article') if ($context == 'com_content.article') { return; } $content = ''; $key = $this->_key($context); if ($article instanceof \Hubzero\Base\Object || $article instanceof \Hubzero\Database\Relational) { $content = $article->get($key); } else { if (isset($article->{$key})) { $content = $article->{$key}; } } $content = ltrim($content); if (!$content) { return; } // Is there a format already applied? if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $content, $matches)) { // Is the format we want? $format = strtolower(trim($matches[1])); if ($format != 'html') { // Not HTML. Do nothing. return; } } $content = preg_replace('/^(<!-- \\{FORMAT:HTML\\} -->)/i', '', $content); if (trim($content)) { // Fix asset paths $content = str_replace('src="/media/system/', 'src="/core/assets/', $content); $content = str_replace('src="/site', 'src="' . substr(PATH_APP, strlen(PATH_ROOT)) . '/site', $content); $content = str_replace("src='/site", "src='" . substr(PATH_APP, strlen(PATH_ROOT)) . '/site', $content); $content = str_replace('href="/media/system/', 'href="/core/assets/', $content); $content = str_replace('href="/site', 'href="' . substr(PATH_APP, strlen(PATH_ROOT)) . '/site', $content); $content = str_replace("href='/site", "href='" . substr(PATH_APP, strlen(PATH_ROOT)) . '/site', $content); include_once __DIR__ . '/parser.php'; if ($this->params->get('unlink', 0)) { $content = preg_replace_callback('/<a.*(?=href="([^"]*)")[^>]*>([^<]*)<\\/a>/uiUs', array(&$this, 'delink'), $content); } $parser = new \Plugins\Content\Formathtml\Parser($params); if ($path = $this->params->get('macropath')) { $parser->addMacroPath($path); } $content = $parser->parse($content); } if ($article instanceof \Hubzero\Base\Object || $article instanceof \Hubzero\Database\Relational) { $article->set($key, $content); } else { $article->{$key} = $content; } }