getgrav / grav-plugin-relatedpages

Grav RelatedPages Plugin
http://getgrav.org
MIT License
17 stars 7 forks source link

substr_count(): Empty substring #25

Open replayshot opened 4 years ago

replayshot commented 4 years ago

For majority of my pages, this plugin works like a charm, but I found this issue with one of the pages. It is online 239 of the php file. Any idea why this happens?

D:\wamp\www\preso\user\plugins\relatedpages\relatedpages.php $cache->save($cache_id, $this->related_pages); } else { $debugger->addMessage("RelatedPages Plugin cache hit."); }

}

/**
 * if enabled on this page, load the JS + CSS theme.
 */
public function onTwigSiteVariables()
{
    $this->grav['twig']->twig_vars['related_pages'] = $this->related_pages;
}

protected function substringCountArray($haystack, array $needle)
{
    $count = 0;
    foreach ((array)$needle as $substring) {
        **$count += substr_count(strtolower($haystack), strtolower($substring));**
    }
    return $count;
}

protected function mergeRelatedPages(array $pages)
{
    foreach ((array) $pages as $path => $score) {
        $page_exists = array_key_exists($path, $this->related_pages);
        if ($score > $this->config['score_threshold'] &&
            (!$page_exists || ($page_exists && $score > $this->related_pages[$path]))) {
            $this->related_pages[$path] = $score;
        }
    }
}

}

Arguments "substr_count(): Empty substring"

replayshot commented 4 years ago

Figured it out. There was an empty tag in the item.md file and that was causing the issue.

tag:

mahagr commented 4 years ago

I think the plugin should work even with empty tags.