Code Duplication    Length = 63-120 lines in 2 locations

class/Utility.php 1 location

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

include/functions.php 1 location

@@ 299-361 (lines=63) @@
296
 */
297
298
// Create the meta keywords based on content
299
function lx_extract_keywords($content) {
300
    global $xoopsTpl, $xoTheme, $xoopsModule, $xoopsModuleConfig;
301
    include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/common.inc.php';
302
    $keywords_count = $xoopsModuleConfig['metakeywordsnum'];
303
    $tmp=array();
304
    if (isset($_SESSION['xoops_keywords_limit'])) {    // Search the "Minimum keyword length"
305
        $limit = $_SESSION['xoops_keywords_limit'];
306
    } else {
307
        $config_handler = xoops_gethandler('config');
308
        $xoopsConfigSearch = $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
309
        $limit=$xoopsConfigSearch['keyword_min'];
310
        $_SESSION['xoops_keywords_limit']=$limit;
311
    }
312
    $myts = MyTextSanitizer::getInstance();
313
    $content = str_replace ("<br />", " ", $content);
314
    $content= $myts->undoHtmlSpecialChars($content);
315
    $content= strip_tags($content);
316
    $content=strtolower($content);
317
    $search_pattern=array("&nbsp;","\t","\r\n","\r","\n",",",".","'",";",":",")","(",'"','?','!','{','}','[',']','<','>','/','+','-','_','\\','*');
318
    $replace_pattern=array(' ',' ',' ',' ',' ',' ',' ',' ','','','','','','','','','','','','','','','','','','','');
319
    $content = str_replace($search_pattern, $replace_pattern, $content);
320
    $keywords=explode(' ',$content);
321
    switch (META_KEYWORDS_ORDER) {
322
    case 1:    // Returns keywords in the same order that they were created in the text
323
            $keywords=array_unique($keywords);
324
        break;
325
326
    case 2:    // the keywords order is made according to the reverse keywords frequency (so the less frequent words appear in first in the list)
327
        $keywords=array_count_values($keywords);
328
        asort($keywords);
329
        $keywords=array_keys($keywords);
330
        break;
331
332
    case 3:    // Same as previous, the only difference is that the most frequent words will appear in first in the list
333
        $keywords=array_count_values($keywords);
334
        arsort($keywords);
335
        $keywords=array_keys($keywords);
336
        break;
337
    }
338
    foreach($keywords as $keyword) {
339
        if (strlen($keyword)>=$limit && !is_numeric($keyword)) {
340
            $tmp[]=$keyword;
341
        }
342
    }
343
    $tmp=array_slice($tmp,0,$keywords_count);
344
    if (count($tmp)>0) {
345
        if (isset($xoTheme) && is_object($xoTheme)) {
346
            $xoTheme->addMeta( 'meta', 'keywords', implode(',',$tmp));
347
        } else {    // Compatibility for old Xoops versions
348
            $xoopsTpl->assign('xoops_meta_keywords', implode(',',$tmp));
349
        }
350
    } else {
351
        if (!isset($config_handler) || !is_object($config_handler)) {
352
            $config_handler = xoops_gethandler('config');
353
        }
354
        $xoopsConfigMetaFooter = $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER);
355
        if (isset($xoTheme) && is_object($xoTheme)) {
356
            $xoTheme->addMeta( 'meta', 'keywords', $xoopsConfigMetaFooter['meta_keywords']);
357
        } else {    // Compatibility for old Xoops versions
358
            $xoopsTpl->assign('xoops_meta_keywords', $xoopsConfigMetaFooter['meta_keywords']);
359
        }
360
    }
361
}
362
363
// Create meta description based on content
364
function lx_get_metadescription($content) {