From 2e6d61a466415664fb4bc100481e9a646af710cf Mon Sep 17 00:00:00 2001 From: Nick Palmer Date: Sat, 26 Jan 2008 23:19:59 +0000 Subject: Add ability to restrict which content types are searchable and modernize permission checking a bit. --- admin/admin_search_inc.php | 37 +++++++++++++++++++++++++++++++++++-- modules/mod_global_search.php | 12 +++++++++--- modules/mod_package_search.php | 10 +++++++--- refresh_functions.php | 6 +++--- search_lib.php | 36 ++++++++++++++++++------------------ templates/admin_search.tpl | 28 ++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 29 deletions(-) diff --git a/admin/admin_search_inc.php b/admin/admin_search_inc.php index 0b543c4..70fc0b5 100644 --- a/admin/admin_search_inc.php +++ b/admin/admin_search_inc.php @@ -1,6 +1,6 @@ assign( 'formSearchToggles', $formSearchToggles ); $gBitSmarty->assign( 'formSearchInts', $formSearchInts ); $gBitSmarty->assign( 'feedback', $feedback ); +$formSearchTypeToggles = array( + 'search_restrict_types' => array( + 'label' => 'Restrict Types', + 'note' => 'If selected the search will be limited to those selected below.' + ), +); +$gBitSmarty->assign( 'formSearchTypeToggles', $formSearchTypeToggles ); + +// allow selection of what packages can have search +foreach( $gLibertySystem->mContentTypes as $cType ) { + $formSearchable['guids']['search_pkg_'.$cType['content_type_guid']] = $cType['content_description']; +} + +if( !empty( $_REQUEST['store_content'] ) ) { + foreach( $formSearchTypeToggles as $item => $data ) { + simple_set_toggle( $item, SEARCH_PKG_NAME ); + } + foreach( array_keys( $formSearchable['guids'] ) as $searchable ) { + $gBitSystem->storeConfig( $searchable, ( ( !empty( $_REQUEST['searchable_content'] ) && in_array( $searchable, $_REQUEST['searchable_content'] ) ) ? 'y' : NULL ), SEARCH_PKG_NAME ); + } + +} + +// check the correct packages in the package selection +foreach( $gLibertySystem->mContentTypes as $cType ) { + if( $gBitSystem->getConfig( 'search_pkg_'.$cType['content_type_guid'] ) ) { + $formSearchable['checked'][] = 'search_pkg_'.$cType['content_type_guid']; + } +} +$gBitSmarty->assign( 'formSearchable', $formSearchable ); + /* usually done in mod_package_search.php - but the module can be not here the first time */ if( empty( $contentTypes ) ) { $contentTypes = array( '' => tra( 'All Content' ) ); foreach( $gLibertySystem->mContentTypes as $cType ) { - $contentTypes[$cType['content_type_guid']] = $cType['content_description']; + if( $gBitSystem->getConfig( 'search_pkg_'.$cType['content_type_guid']) ) { + $contentTypes[$cType['content_type_guid']] = $cType['content_description']; + } } $gBitSmarty->assign( 'contentTypes', $contentTypes ); } diff --git a/modules/mod_global_search.php b/modules/mod_global_search.php index 053ffeb..0767a8d 100644 --- a/modules/mod_global_search.php +++ b/modules/mod_global_search.php @@ -1,6 +1,6 @@ tra( 'All Content' ) ); foreach( $gLibertySystem->mContentTypes as $cType ) { - $contentTypes[$cType['content_type_guid']] = $cType['content_description']; + if (SearchLib::has_permission($cType["content_type_guid"]) + and ( ! $gBitSystem->getConfig('search_restrict_types') || + $gBitSystem->getConfig('search_pkg_'.$cType["content_type_guid"]) ) ) { + $contentTypes[$cType['content_type_guid']] = $cType['content_description']; + } } } $gBitSmarty->assign( 'contentTypes', $contentTypes ); diff --git a/modules/mod_package_search.php b/modules/mod_package_search.php index 4fc3606..0a4d9e1 100644 --- a/modules/mod_package_search.php +++ b/modules/mod_package_search.php @@ -1,6 +1,6 @@ tra( 'All Content' ) ); foreach( $gLibertySystem->mContentTypes as $cType ) { - $contentTypes[$cType['content_type_guid']] = $cType['content_description']; + if (SearchLib::has_permission($cType["content_type_guid"]) + and ( ! $gBitSystem->getConfig('search_restrict_types') || + $gBitSystem->getConfig('search_pkg_'.$cType["content_type_guid"]) ) ) { + $contentTypes[$cType['content_type_guid']] = $cType['content_description']; + } } } $gBitSmarty->assign( 'contentTypes', $contentTypes ); diff --git a/refresh_functions.php b/refresh_functions.php index 0959a94..18968a8 100644 --- a/refresh_functions.php +++ b/refresh_functions.php @@ -1,6 +1,6 @@ mContentTypes as $contentType ) { if (( $pParamHash['content_type_guid'] == $contentType["content_type_guid"] or $pParamHash['content_type_guid'] == "" ) // pages ? - and $this->has_permission($contentType["content_type_guid"])) { + and $this->has_permission($contentType["content_type_guid"]) + and ( ! $gBitSystem->getConfig('search_restrict_types') || + $gBitSystem->getConfig('search_pkg_'.$contentType["content_type_guid"]) ) ) { $allowed[] = $contentType["content_type_guid"]; } } @@ -231,22 +233,20 @@ class SearchLib extends BitBase { } } - function has_permission($pContentType = "") { - global $gBitUser; - $ret = false; - switch ($pContentType) { - case "bitarticle" : $perm = "p_articles_read"; break; - case "bitpage" : $perm = "p_wiki_view_page"; break; - case "bitblog" : $perm = "p_blogs_view"; break; - case "bitblogpost" : $perm = "p_blogs_view"; break; - case "bitcomment" : $perm = "p_liberty_read_comments"; break; - case "fisheyegallery" : $perm = "p_fisheye_view"; break; - case "fisheyeitem" : $perm = "p_fisheye_view"; break; - case "treasurygallery" : $perm = "p_treasury_view"; break; - case "treasuryitem" : $perm = "p_treasury_view"; break; - default : $perm = ""; break; + function has_permission($pContentType = NULL) { + global $gBitUser, $gLibertySystem; + + if ( ! empty( $pContentType ) ) { + $object = $gLibertySystem->getLibertyObject(1, $pContentType, FALSE); + if ( ! empty( $object ) ) { + // Note that we can't do verify access here because + // we are using a generic object but we can at least get a + // basic permission check here. + return $object->hasViewPermission(FALSE); + } } - return $gBitUser->hasPermission($perm); + + return FALSE; } } # class SearchLib diff --git a/templates/admin_search.tpl b/templates/admin_search.tpl index 0077865..69113cc 100644 --- a/templates/admin_search.tpl +++ b/templates/admin_search.tpl @@ -32,6 +32,34 @@ {/form} {/jstab} + {jstab title="Searchable Content"} + {form legend="Searchable Content"} + {foreach from=$formSearchTypeToggles key=item item=output} +
+ {formlabel label=`$output.label` for=$item} + {forminput} + {html_checkboxes name="$item" values="y" checked=$gBitSystem->getConfig($item) labels=false id=$item} + {formhelp note=`$output.note` page=`$output.page`} + {/forminput} +
+ {/foreach} + + +
+ {formlabel label="Searchable Content"} + {forminput} + {html_checkboxes options=$formSearchable.guids value=y name=searchable_content separator="
" checked=$formSearchable.checked} + {formhelp note="Here you can select what content can be searched."} + {/forminput} +
+ +
+ +
+ {/form} + + {/jstab} + {jstab title="Delete / Rebuild Index"} {formfeedback hash=$feedback} -- cgit v1.3