Code Duplication    Length = 134-134 lines in 2 locations

class/utility.php 1 location

@@ 530-663 (lines=134) @@
527
     * @param $content
528
     * @return string
529
     */
530
    public static function createMetaKeywords($content)
531
    {
532
        include XOOPS_ROOT_PATH . '/modules/news/config.php';
533
        require_once XOOPS_ROOT_PATH . '/modules/news/class/blacklist.php';
534
        require_once XOOPS_ROOT_PATH . '/modules/news/class/registryfile.php';
535
536
        if (!$cfg['meta_keywords_auto_generate']) {
537
            return '';
538
        }
539
        $registry = new news_registryfile('news_metagen_options.txt');
540
        //    $tcontent = '';
541
        $tcontent = $registry->getfile();
542
        if ('' !== xoops_trim($tcontent)) {
543
            list($keywordscount, $keywordsorder) = explode(',', $tcontent);
544
        } else {
545
            $keywordscount = $cfg['meta_keywords_count'];
546
            $keywordsorder = $cfg['meta_keywords_order'];
547
        }
548
549
        $tmp = [];
550
        // Search for the "Minimum keyword length"
551
        if (isset($_SESSION['news_keywords_limit'])) {
552
            $limit = $_SESSION['news_keywords_limit'];
553
        } else {
554
            $configHandler                   = xoops_getHandler('config');
555
            $xoopsConfigSearch               = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH);
556
            $limit                           = $xoopsConfigSearch['keyword_min'];
557
            $_SESSION['news_keywords_limit'] = $limit;
558
        }
559
        $myts            = MyTextSanitizer::getInstance();
560
        $content         = str_replace('<br>', ' ', $content);
561
        $content         = $myts->undoHtmlSpecialChars($content);
562
        $content         = strip_tags($content);
563
        $content         = strtolower($content);
564
        $search_pattern  = [
565
            '&nbsp;',
566
            "\t",
567
            "\r\n",
568
            "\r",
569
            "\n",
570
            ',',
571
            '.',
572
            "'",
573
            ';',
574
            ':',
575
            ')',
576
            '(',
577
            '"',
578
            '?',
579
            '!',
580
            '{',
581
            '}',
582
            '[',
583
            ']',
584
            '<',
585
            '>',
586
            '/',
587
            '+',
588
            '-',
589
            '_',
590
            '\\',
591
            '*'
592
        ];
593
        $replace_pattern = [
594
            ' ',
595
            ' ',
596
            ' ',
597
            ' ',
598
            ' ',
599
            ' ',
600
            ' ',
601
            ' ',
602
            '',
603
            '',
604
            '',
605
            '',
606
            '',
607
            '',
608
            '',
609
            '',
610
            '',
611
            '',
612
            '',
613
            '',
614
            '',
615
            '',
616
            '',
617
            '',
618
            '',
619
            '',
620
            ''
621
        ];
622
        $content         = str_replace($search_pattern, $replace_pattern, $content);
623
        $keywords        = explode(' ', $content);
624
        switch ($keywordsorder) {
625
            case 0: // Ordre d'apparition dans le texte
626
                $keywords = array_unique($keywords);
627
                break;
628
            case 1: // Ordre de fréquence des mots
629
                $keywords = array_count_values($keywords);
630
                asort($keywords);
631
                $keywords = array_keys($keywords);
632
                break;
633
            case 2: // Ordre inverse de la fréquence des mots
634
                $keywords = array_count_values($keywords);
635
                arsort($keywords);
636
                $keywords = array_keys($keywords);
637
                break;
638
        }
639
        // Remove black listed words
640
        $metablack = new news_blacklist();
641
        $words     = $metablack->getAllKeywords();
642
        $keywords  = $metablack->remove_blacklisted($keywords);
643
644
        foreach ($keywords as $keyword) {
645
            if (strlen($keyword) >= $limit && !is_numeric($keyword)) {
646
                $tmp[] = $keyword;
647
            }
648
        }
649
        $tmp = array_slice($tmp, 0, $keywordscount);
650
        if (count($tmp) > 0) {
651
            return implode(',', $tmp);
652
        } else {
653
            if (!isset($configHandler) || !is_object($configHandler)) {
654
                $configHandler = xoops_getHandler('config');
655
            }
656
            $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
657
            if (isset($xoopsConfigMetaFooter['meta_keywords'])) {
658
                return $xoopsConfigMetaFooter['meta_keywords'];
659
            } else {
660
                return '';
661
            }
662
        }
663
    }
664
665
    /**
666
     * Remove module's cache

include/functions.php 1 location

@@ 408-541 (lines=134) @@
405
 * @param $content
406
 * @return string
407
 */
408
function news_createmeta_keywords($content)
409
{
410
    include XOOPS_ROOT_PATH . '/modules/news/config.php';
411
    require_once XOOPS_ROOT_PATH . '/modules/news/class/blacklist.php';
412
    require_once XOOPS_ROOT_PATH . '/modules/news/class/registryfile.php';
413
414
    if (!$cfg['meta_keywords_auto_generate']) {
415
        return '';
416
    }
417
    $registry = new news_registryfile('news_metagen_options.txt');
418
    //    $tcontent = '';
419
    $tcontent = $registry->getfile();
420
    if ('' !== xoops_trim($tcontent)) {
421
        list($keywordscount, $keywordsorder) = explode(',', $tcontent);
422
    } else {
423
        $keywordscount = $cfg['meta_keywords_count'];
424
        $keywordsorder = $cfg['meta_keywords_order'];
425
    }
426
427
    $tmp = [];
428
    // Search for the "Minimum keyword length"
429
    if (isset($_SESSION['news_keywords_limit'])) {
430
        $limit = $_SESSION['news_keywords_limit'];
431
    } else {
432
        $configHandler                   = xoops_getHandler('config');
433
        $xoopsConfigSearch               = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH);
434
        $limit                           = $xoopsConfigSearch['keyword_min'];
435
        $_SESSION['news_keywords_limit'] = $limit;
436
    }
437
    $myts            = MyTextSanitizer::getInstance();
438
    $content         = str_replace('<br>', ' ', $content);
439
    $content         = $myts->undoHtmlSpecialChars($content);
440
    $content         = strip_tags($content);
441
    $content         = strtolower($content);
442
    $search_pattern  = [
443
        '&nbsp;',
444
        "\t",
445
        "\r\n",
446
        "\r",
447
        "\n",
448
        ',',
449
        '.',
450
        "'",
451
        ';',
452
        ':',
453
        ')',
454
        '(',
455
        '"',
456
        '?',
457
        '!',
458
        '{',
459
        '}',
460
        '[',
461
        ']',
462
        '<',
463
        '>',
464
        '/',
465
        '+',
466
        '-',
467
        '_',
468
        '\\',
469
        '*'
470
    ];
471
    $replace_pattern = [
472
        ' ',
473
        ' ',
474
        ' ',
475
        ' ',
476
        ' ',
477
        ' ',
478
        ' ',
479
        ' ',
480
        '',
481
        '',
482
        '',
483
        '',
484
        '',
485
        '',
486
        '',
487
        '',
488
        '',
489
        '',
490
        '',
491
        '',
492
        '',
493
        '',
494
        '',
495
        '',
496
        '',
497
        '',
498
        ''
499
    ];
500
    $content         = str_replace($search_pattern, $replace_pattern, $content);
501
    $keywords        = explode(' ', $content);
502
    switch ($keywordsorder) {
503
        case 0: // Ordre d'apparition dans le texte
504
            $keywords = array_unique($keywords);
505
            break;
506
        case 1: // Ordre de fréquence des mots
507
            $keywords = array_count_values($keywords);
508
            asort($keywords);
509
            $keywords = array_keys($keywords);
510
            break;
511
        case 2: // Ordre inverse de la fréquence des mots
512
            $keywords = array_count_values($keywords);
513
            arsort($keywords);
514
            $keywords = array_keys($keywords);
515
            break;
516
    }
517
    // Remove black listed words
518
    $metablack = new news_blacklist();
519
    $words     = $metablack->getAllKeywords();
520
    $keywords  = $metablack->remove_blacklisted($keywords);
521
522
    foreach ($keywords as $keyword) {
523
        if (strlen($keyword) >= $limit && !is_numeric($keyword)) {
524
            $tmp[] = $keyword;
525
        }
526
    }
527
    $tmp = array_slice($tmp, 0, $keywordscount);
528
    if (count($tmp) > 0) {
529
        return implode(',', $tmp);
530
    } else {
531
        if (!isset($configHandler) || !is_object($configHandler)) {
532
            $configHandler = xoops_getHandler('config');
533
        }
534
        $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
535
        if (isset($xoopsConfigMetaFooter['meta_keywords'])) {
536
            return $xoopsConfigMetaFooter['meta_keywords'];
537
        } else {
538
            return '';
539
        }
540
    }
541
}
542
543
/**
544
 * Remove module's cache