Code Duplication    Length = 30-30 lines in 2 locations

class/utility.php 1 location

@@ 834-863 (lines=30) @@
831
     * @param $string
832
     * @return string
833
     */
834
    public static function closeTags($string)
835
    {
836
        // match opened tags
837
        if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
838
            $start_tags = $start_tags[1];
839
            // match closed tags
840
            if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
841
                $complete_tags = [];
842
                $end_tags      = $end_tags[1];
843
844
                foreach ($start_tags as $key => $val) {
845
                    $posb = array_search($val, $end_tags);
846
                    if (is_int($posb)) {
847
                        unset($end_tags[$posb]);
848
                    } else {
849
                        $complete_tags[] = $val;
850
                    }
851
                }
852
            } else {
853
                $complete_tags = $start_tags;
854
            }
855
856
            $complete_tags = array_reverse($complete_tags);
857
            for ($i = 0, $iMax = count($complete_tags); $i < $iMax; ++$i) {
858
                $string .= '</' . $complete_tags[$i] . '>';
859
            }
860
        }
861
862
        return $string;
863
    }
864
865
    /**
866
     * Smarty truncate_tagsafe modifier plugin

include/functions.php 1 location

@@ 712-741 (lines=30) @@
709
 * @param $string
710
 * @return string
711
 */
712
function news_close_tags($string)
713
{
714
    // match opened tags
715
    if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
716
        $start_tags = $start_tags[1];
717
        // match closed tags
718
        if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
719
            $complete_tags = [];
720
            $end_tags      = $end_tags[1];
721
722
            foreach ($start_tags as $key => $val) {
723
                $posb = array_search($val, $end_tags);
724
                if (is_int($posb)) {
725
                    unset($end_tags[$posb]);
726
                } else {
727
                    $complete_tags[] = $val;
728
                }
729
            }
730
        } else {
731
            $complete_tags = $start_tags;
732
        }
733
734
        $complete_tags = array_reverse($complete_tags);
735
        for ($i = 0, $iMax = count($complete_tags); $i < $iMax; ++$i) {
736
            $string .= '</' . $complete_tags[$i] . '>';
737
        }
738
    }
739
740
    return $string;
741
}
742
743
/**
744
 * Smarty truncate_tagsafe modifier plugin