Code Duplication    Length = 63-120 lines in 2 locations

class/Utility.php 1 location

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

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
                    '',