+ if (!count($inputTags)) {
+ // no input tags
+ return $this->noFilter($visibility);
+ }
+
+ // build regex from all tags
+ $re = '/^' . implode(array_map("self::tag2regex", $inputTags)) . '.*$/';
+ if (!$casesensitive) {
+ // make regex case insensitive
+ $re .= 'i';
+ }
+
+ // create resulting array
+ $filtered = array();
+
+ // iterate over each link
+ foreach ($this->links as $key => $link) {
+ // check level of visibility
+ // ignore non private links when 'privateonly' is on.
+ if ($visibility !== 'all') {
+ if (! $link['private'] && $visibility === 'private') {
+ continue;
+ } elseif ($link['private'] && $visibility === 'public') {
+ continue;
+ }
+ }
+ $search = $link['tags']; // build search string, start with tags of current link
+ if (strlen(trim($link['description'])) && strpos($link['description'], '#') !== false) {
+ // description given and at least one possible tag found
+ $descTags = array();
+ // find all tags in the form of #tag in the description
+ preg_match_all(
+ '/(?<![' . self::$HASHTAG_CHARS . '])#([' . self::$HASHTAG_CHARS . ']+?)\b/sm',
+ $link['description'],
+ $descTags
+ );
+ if (count($descTags[1])) {
+ // there were some tags in the description, add them to the search string
+ $search .= ' ' . implode(' ', $descTags[1]);
+ }
+ };
+ // match regular expression with search string
+ if (!preg_match($re, $search)) {
+ // this entry does _not_ match our regex