Example #1
0
 function replace(&$string, $area = 'articles', $article = '')
 {
     if (!is_string($string) || $string == '') {
         return;
     }
     $array = $this->stringToSplitArray($string, $this->src_params->regex);
     $array_count = count($array);
     if ($array_count <= 1) {
         return;
     }
     for ($i = 1; $i < $array_count - 1; $i++) {
         if (!fmod($i, 2) || !preg_match($this->src_params->regex, $array[$i], $match)) {
             continue;
         }
         $data = NNTags::getTagValues(trim($match['data']), array());
         $content = trim($match['content']);
         $remove_html = !in_array('0', $data->params);
         // Remove html tags if code is placed via the WYSIWYG editor
         if ($remove_html) {
             $this->cleanText($content);
         }
         // Add the include file if file=... or include=... is used in the {source} tag
         $file = !empty($data->file) ? $data->file : (!empty($data->include) ? $data->include : '');
         if (!empty($file) && JFile::exists(JPATH_SITE . '/' . $file)) {
             $content = '<?php include JPATH_SITE . \'' . $this->src_params->include_path . $file . '\'; ?>' . $content;
         }
         $this->replaceTags($content, $area, $article);
         if (!$remove_html) {
             $array[$i] = $match['start_pre'] . $match['start_post'] . $content . $match['end_pre'] . $match['end_post'];
             continue;
         }
         $trim = isset($data->trim) ? $data->trim : $this->src_params->trim;
         if ($trim) {
             $tags = NNTags::cleanSurroundingTags(array('start_pre' => $match['start_pre'], 'start_post' => $match['start_post']));
             $match = array_merge($match, $tags);
             $tags = NNTags::cleanSurroundingTags(array('end_pre' => $match['end_pre'], 'end_post' => $match['end_post']));
             $match = array_merge($match, $tags);
             $tags = NNTags::cleanSurroundingTags(array('start_pre' => $match['start_pre'], 'end_post' => $match['end_post']));
             $match = array_merge($match, $tags);
         }
         $tags = NNTags::cleanSurroundingTags(array('start_pre' => $match['start_pre'], 'start_post' => $match['start_post'], 'end_pre' => $match['end_pre'], 'end_post' => $match['end_post']));
         $array[$i] = $tags['start_pre'] . $tags['start_post'] . $content . $tags['end_pre'] . $tags['end_post'];
     }
     $string = implode('', $array);
 }