$counter = 0; foreach ($search_result as $cat_id => $cat_contents) { $tmp_result_html = ''; foreach ($cat_contents as $cat_content_item) { $b_permission = false; //Groups Permission Check if ($faqconfig->get('main.permLevel') == 'medium') { $perm_group = $faqGroup->fetch($cat_content_item->id); foreach ($current_groups as $index => $value) { if ($value == $perm_group->group_id) { $b_permission = true; } } } if ($faqconfig->get('main.permLevel') == 'basic' || $b_permission) { $perm_user = $faqUser->fetch($cat_content_item->id); foreach ($perm_user as $value) { if ($value == -1) { $b_permission = true; break; } elseif ((int) $value == $current_user) { $b_permission = true; break; } else { $b_permission = false; } } } if (!$b_permission) { continue; }
} else { $logging = new PMF_Logging(); $logging->logAdmin($user, 'Beitragcreate'); $url_variables = 'insertentry'; if (!is_array($categories)) { $categories = array(); } } // Revisions $revisionid_selected = PMF_Filter::filterInput(INPUT_POST, 'revisionid_selected', FILTER_VALIDATE_INT); if (is_null($revisionid_selected)) { $revisionid_selected = $faqData['revision_id']; } // Permissions $faqUser = new PMF_Faq_User(); $user_permission = $faqUser->fetch($faqData['id']); if (is_object($user_permission) || $user_permission->user_id == -1) { $all_users = true; $restricted_users = false; } else { $all_users = false; $restricted_users = true; } $faqGroup = new PMF_Faq_Group(); $group_permission = $faqGroup->fetch($faqData['id']); if (is_object($group_permission) || $group_permission->group_id == -1) { $all_groups = true; $restricted_groups = false; } else { $all_groups = false; $restricted_groups = true;
/** * Check on user and group permissions and on duplicate FAQs * * @param array $resultset Array with search results * * @return void */ public function reviewResultset(array $resultset) { $this->setResultset($resultset); $faqUser = new PMF_Faq_User(); $faqGroup = new PMF_Faq_Group(); $duplicateResults = array(); $currentUserId = $this->user->getUserId(); if ('medium' == PMF_Configuration::getInstance()->get('main.permLevel')) { $currentGroupIds = $this->user->perm->getUserGroups($currentUserId); } foreach ($this->rawResultset as $index => $result) { $permission = false; // check permissions for groups if ('medium' == PMF_Configuration::getInstance()->get('main.permLevel')) { $groupPerm = $faqGroup->fetch($result->id); if (count($groupPerm) && in_array($groupPerm->group_id, $currentGroupIds)) { $permission = true; } } // check permission for user if ($permission || 'basic' == PMF_Configuration::getInstance()->get('main.permLevel')) { $userPerm = $faqUser->fetch($result->id); if (-1 == $userPerm->user_id || $this->user->getUserId() == $userPerm->user_id) { $permission = true; } else { $permission = false; } } // check on duplicates if (!isset($duplicateResults[$result->id])) { $duplicateResults[$result->id] = 1; } else { ++$duplicateResults[$result->id]; continue; } if ($permission) { $this->reviewedResultset[] = $result; } } $this->setNumberOfResults($this->reviewedResultset); }
/** * The main search function for the full text search * * TODO: add filter for (X)HTML tag names and attributes! * * @param string Text/Number (solution id) * @param string '%' to avoid any category filtering * @param boolean true to search over all languages * @param boolean true to disable the results paging * @param boolean true to use it for Instant Response * @return string * @access public * @author Thorsten Rinne <*****@*****.**> * @author Matteo Scaramuccia <*****@*****.**> * @author Adrianna Musiol <*****@*****.**> * @since 2002-09-16 */ function searchEngine($searchterm, $cat = '%', $allLanguages = true, $hasMore = false, $instantRespnse = false) { global $sids, $PMF_LANG, $plr, $LANGCODE, $faq, $current_user, $current_groups, $categoryLayout; $_searchterm = PMF_htmlentities(stripslashes($searchterm), ENT_QUOTES, 'utf-8'); $seite = 1; $output = ''; $num = 0; $searchItems = array(); $langs = true == $allLanguages ? '&langs=all' : ''; $seite = PMF_Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1); $db = PMF_Db::getInstance(); $faqconfig = PMF_Configuration::getInstance(); $result = getSearchData(htmlentities($searchterm, ENT_COMPAT, 'utf-8'), true, $cat, $allLanguages); $num = $db->numRows($result); if (0 == $num) { $output = $PMF_LANG['err_noArticles']; } $confPerPage = $faqconfig->get('main.numberOfRecordsPerPage'); $pages = ceil($num / $confPerPage); $last = $seite * $confPerPage; $first = $last - $confPerPage; if ($last > $num) { $last = $num; } if ($num > 0) { $output .= '<p>' . $plr->GetMsg('plmsgSearchAmount', $num); if ($hasMore && $pages > 1) { $output .= sprintf($PMF_LANG['msgInstantResponseMaxRecords'], $confPerPage); } $output .= "</p>\n"; if (!$hasMore && $pages > 1) { $output .= "<p><strong>" . $PMF_LANG["msgPage"] . $seite . " " . $PMF_LANG["msgVoteFrom"] . " " . $plr->GetMsg('plmsgPagesTotal', $pages) . "</strong></p>"; } $output .= "<ul class=\"phpmyfaq_ul\">\n"; $faqUser = new PMF_Faq_User(); $faqGroup = new PMF_Faq_Group(); $counter = $displayedCounter = 0; while (($row = $db->fetchObject($result)) && $displayedCounter < $confPerPage) { $counter++; if ($counter <= $first) { continue; } $displayedCounter++; $b_permission = false; //Groups Permission Check if ($faqconfig->get('main.permLevel') == 'medium') { $perm_group = $faqGroup->fetch($row->id); foreach ($current_groups as $value) { if ($value == $perm_group->group_id) { $b_permission = true; } } } if ($faqconfig->get('main.permLevel') == 'basic' || $b_permission) { $perm_user = $faqUser->fetch($row->id); foreach ($perm_user as $value) { if ($value == -1) { $b_permission = true; break; } elseif ((int) $value == $current_user) { $b_permission = true; break; } else { $b_permission = false; } } } if ($b_permission) { $rubriktext = $categoryLayout->renderBreadcrumb(array($row->category_id)); $thema = chopString($row->thema, 15); $content = chopString(strip_tags($row->content), 25); $searchterm = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']', '"'), '', $searchterm); $searchterm = preg_quote($searchterm, '/'); $searchItems = explode(' ', $searchterm); if (PMF_String::strlen($searchItems[0]) > 1) { foreach ($searchItems as $item) { if (PMF_String::strlen($item) > 2) { $thema = PMF_String::preg_replace_callback('/' . '(' . $item . '="[^"]*")|' . '((href|src|title|alt|class|style|id|name|dir|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup)="[^"]*' . $item . '[^"]*")|' . '(' . $item . ')' . '/mis', "highlight_no_links", $thema); $content = PMF_String::preg_replace_callback('/' . '(' . $item . '="[^"]*")|' . '((href|src|title|alt|class|style|id|name|dir|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup)="[^"]*' . $item . '[^"]*")|' . '(' . $item . ')' . '/mis', "highlight_no_links", $content); } } } // Print the link to the faq record $url = sprintf('?%saction=artikel&cat=%d&id=%d&artlang=%s&highlight=%s', $sids, $row->category_id, $row->id, $row->lang, urlencode($_searchterm)); if ($instantRespnse) { $currentUrl = PMF_Link::getSystemRelativeUri('ajaxresponse.php') . 'index.php'; } else { $currentUrl = PMF_Link::getSystemRelativeUri(); } $oLink = new PMF_Link($currentUrl . $url); $oLink->itemTitle = $row->thema; $oLink->text = $thema; $oLink->tooltip = $row->thema; $output .= '<li><strong>' . $rubriktext . '</strong>: ' . $oLink->toHtmlAnchor() . '<br />' . '<div class="searchpreview"><strong>' . $PMF_LANG['msgSearchContent'] . '</strong> ' . $content . '...</div>' . '<br /></li>' . "\n"; } } $output .= "</ul>\n"; } else { $output = $PMF_LANG["err_noArticles"]; } if (!$hasMore && $num > $confPerPage) { if ($faqconfig->get('main.enableRewriteRules')) { $baseUrl = sprintf("search.html?search=%s&seite=%d%s&searchcategory=%d", urlencode($_searchterm), $seite, $langs, $cat); } else { $baseUrl = PMF_Link::getSystemRelativeUri() . '?' . (empty($sids) ? '' : "{$sids}&") . 'action=search&search=' . urlencode($_searchterm) . '&seite=' . $seite . $langs . "&searchcategory=" . $cat; } $options = array('baseUrl' => $baseUrl, 'total' => $num, 'perPage' => $confPerPage, 'pageParamName' => 'seite', 'nextPageLinkTpl' => '<a href="{LINK_URL}">' . $PMF_LANG["msgNext"] . '</a>', 'prevPageLinkTpl' => '<a href="{LINK_URL}">' . $PMF_LANG["msgPrevious"] . '</a>', 'layoutTpl' => '<p align="center"><strong>{LAYOUT_CONTENT}</strong></p>'); $pagination = new PMF_Pagination($options); $output .= $pagination->render(); } return $output; }