Code Duplication    Length = 63-120 lines in 2 locations

include/functions.php 1 location

@@ 367-429 (lines=63) @@
364
 */
365
366
// Create the meta keywords based on content
367
function lx_extract_keywords($content) {
368
    global $xoopsTpl, $xoTheme, $xoopsModule, $xoopsModuleConfig;
369
    include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/common.inc.php';
370
    $keywords_count = $xoopsModuleConfig['metakeywordsnum'];
371
    $tmp=array();
372
    if (isset($_SESSION['xoops_keywords_limit'])) {    // Search the "Minimum keyword length"
373
        $limit = $_SESSION['xoops_keywords_limit'];
374
    } else {
375
        $config_handler = xoops_gethandler('config');
376
        $xoopsConfigSearch = $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
377
        $limit=$xoopsConfigSearch['keyword_min'];
378
        $_SESSION['xoops_keywords_limit']=$limit;
379
    }
380
    $myts = MyTextSanitizer::getInstance();
381
    $content = str_replace ("<br />", " ", $content);
382
    $content= $myts->undoHtmlSpecialChars($content);
383
    $content= strip_tags($content);
384
    $content=strtolower($content);
385
    $search_pattern=[
386
                    "&nbsp;",
387
                    "\t",
388
                    "\r\n",
389
                    "\r",
390
                    "\n",
391
                    ",",
392
                    ".",
393
                    "'",
394
                    ";",
395
                    ":",
396
                    ")",
397
                    "(",
398
                    '"',
399
                    '?',
400
                    '!',
401
                    '{',
402
                    '}',
403
                    '[',
404
                    ']',
405
                    '<',
406
                    '>',
407
                    '/',
408
                    '+',
409
                    '-',
410
                    '_',
411
                    '\\',
412
                    '*'
413
                    ];
414
    $replace_pattern=[
415
                    ' ',
416
                    ' ',
417
                    ' ',
418
                    ' ',
419
                    ' ',
420
                    ' ',
421
                    ' ',
422
                    ' ',
423
                    '',
424
                    '',
425
                    '',
426
                    '',
427
                    '',
428
                    '',
429
                    '',
430
                    '',
431
                    '',
432
                    '',

class/Utility.php 1 location

@@ 634-753 (lines=120) @@
631
    /**
632
     * @param $content
633
     */
634
public static function extractKeywords($content)
635
{
636
    global $xoopsTpl, $xoTheme, $xoopsModule, $xoopsModuleConfig;
637
    include_once XOOPS_ROOT_PATH . '/modules/lexikon/include/common.inc.php';
638
    $keywords_count = $xoopsModuleConfig['metakeywordsnum'];
639
    $tmp            = [];
640
    if (isset($_SESSION['xoops_keywords_limit'])) {    // Search the "Minimum keyword length"
641
            $limit = $_SESSION['xoops_keywords_limit'];
642
    } else {
643
        $configHandler                    = xoops_getHandler('config');
644
        $xoopsConfigSearch                = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH);
645
        $limit                            = $xoopsConfigSearch['keyword_min'];
646
        $_SESSION['xoops_keywords_limit'] = $limit;
647
    }
648
    $myts            = MyTextSanitizer::getInstance();
649
    $content         = str_replace('<br>', ' ', $content);
650
    $content         = $myts->undoHtmlSpecialChars($content);
651
    $content         = strip_tags($content);
652
    $content         = strtolower($content);
653
    $search_pattern  = [
654
            '&nbsp;',
655
            "\t",
656
            "\r\n",
657
            "\r",
658
            "\n",
659
            ',',
660
            '.',
661
            "'",
662
            ';',
663
            ':',
664
            ')',
665
            '(',
666
            '"',
667
            '?',
668
            '!',
669
            '{',
670
            '}',
671
            '[',
672
            ']',
673
            '<',
674
            '>',
675
            '/',
676
            '+',
677
            '-',
678
            '_',
679
            '\\',
680
            '*'
681
        ];
682
    $replace_pattern = [
683
            ' ',
684
            ' ',
685
            ' ',
686
            ' ',
687
            ' ',
688
            ' ',
689
            ' ',
690
            ' ',
691
            '',
692
            '',
693
            '',
694
            '',
695
            '',
696
            '',
697
            '',
698
            '',
699
            '',
700
            '',
701
            '',
702
            '',
703
            '',
704
            '',
705
            '',
706
            '',
707
            '',
708
            '',
709
            ''
710
        ];
711
    $content         = str_replace($search_pattern, $replace_pattern, $content);
712
    $keywords        = explode(' ', $content);
713
    switch (META_KEYWORDS_ORDER) {
714
            case 1:    // Returns keywords in the same order that they were created in the text
715
                $keywords = array_unique($keywords);
716
                break;
717
718
            case 2:    // the keywords order is made according to the reverse keywords frequency (so the less frequent words appear in first in the list)
719
                $keywords = array_count_values($keywords);
720
                asort($keywords);
721
                $keywords = array_keys($keywords);
722
                break;
723
724
            case 3:    // Same as previous, the only difference is that the most frequent words will appear in first in the list
725
                $keywords = array_count_values($keywords);
726
                arsort($keywords);
727
                $keywords = array_keys($keywords);
728
                break;
729
        }
730
    foreach ($keywords as $keyword) {
731
        if (strlen($keyword) >= $limit && !is_numeric($keyword)) {
732
            $tmp[] = $keyword;
733
        }
734
    }
735
    $tmp = array_slice($tmp, 0, $keywords_count);
736
    if (count($tmp) > 0) {
737
        if (isset($xoTheme) && is_object($xoTheme)) {
738
            $xoTheme->addMeta('meta', 'keywords', implode(',', $tmp));
739
        } else {    // Compatibility for old Xoops versions
740
                $xoopsTpl->assign('xoops_meta_keywords', implode(',', $tmp));
741
        }
742
    } else {
743
        if (!isset($configHandler) || !is_object($configHandler)) {
744
            $configHandler = xoops_getHandler('config');
745
        }
746
        $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
747
        if (isset($xoTheme) && is_object($xoTheme)) {
748
            $xoTheme->addMeta('meta', 'keywords', $xoopsConfigMetaFooter['meta_keywords']);
749
        } else {    // Compatibility for old Xoops versions
750
                $xoopsTpl->assign('xoops_meta_keywords', $xoopsConfigMetaFooter['meta_keywords']);
751
        }
752
    }
753
}
754
755
    // Create meta description based on content
756
    /**