summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Palmer <nick@sluggardy.net>2008-01-26 23:19:59 +0000
committerNick Palmer <nick@sluggardy.net>2008-01-26 23:19:59 +0000
commit2e6d61a466415664fb4bc100481e9a646af710cf (patch)
tree811aaa5d7f79c6fb905d69508135be75260c6b0c
parentf25323480ca8496e65c25e636e403d45187875be (diff)
downloadsearch-2e6d61a466415664fb4bc100481e9a646af710cf.tar.gz
search-2e6d61a466415664fb4bc100481e9a646af710cf.tar.bz2
search-2e6d61a466415664fb4bc100481e9a646af710cf.zip
Add ability to restrict which content types are searchable and modernize permission checking a bit.
-rw-r--r--admin/admin_search_inc.php37
-rw-r--r--modules/mod_global_search.php12
-rw-r--r--modules/mod_package_search.php10
-rw-r--r--refresh_functions.php6
-rw-r--r--search_lib.php36
-rw-r--r--templates/admin_search.tpl28
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 @@
<?php
-// $Header: /cvsroot/bitweaver/_bit_search/admin/admin_search_inc.php,v 1.14 2006/12/31 13:01:16 squareing Exp $
+// $Header: /cvsroot/bitweaver/_bit_search/admin/admin_search_inc.php,v 1.15 2008/01/26 23:19:59 nickpalmer Exp $
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
@@ -82,11 +82,44 @@ $gBitSmarty->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 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_search/modules/mod_global_search.php,v 1.7 2006/12/31 13:01:16 squareing Exp $
+ * $Header: /cvsroot/bitweaver/_bit_search/modules/mod_global_search.php,v 1.8 2008/01/26 23:19:59 nickpalmer Exp $
*
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
@@ -8,17 +8,23 @@
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: mod_global_search.php,v 1.7 2006/12/31 13:01:16 squareing Exp $
+ * $Id: mod_global_search.php,v 1.8 2008/01/26 23:19:59 nickpalmer Exp $
* @author Luis Argerich (lrargerich@yahoo.com)
* @package search
* @subpackage modules
*/
global $gLibertySystem;
+require_once(SEARCH_PKG_PATH."search_lib.php");
+
if( empty( $contentTypes ) ) {
$contentTypes = array( '' => 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 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_search/modules/mod_package_search.php,v 1.10 2006/12/31 13:01:16 squareing Exp $
+ * $Header: /cvsroot/bitweaver/_bit_search/modules/mod_package_search.php,v 1.11 2008/01/26 23:19:59 nickpalmer Exp $
*
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
@@ -8,7 +8,7 @@
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: mod_package_search.php,v 1.10 2006/12/31 13:01:16 squareing Exp $
+ * $Id: mod_package_search.php,v 1.11 2008/01/26 23:19:59 nickpalmer Exp $
* @author Luis Argerich (lrargerich@yahoo.com)
* @package search
* @subpackage modules
@@ -30,7 +30,11 @@
if( empty( $contentTypes ) ) {
$contentTypes = array( '' => 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 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_search/refresh_functions.php,v 1.30 2007/12/04 17:42:09 joasch Exp $
+ * $Header: /cvsroot/bitweaver/_bit_search/refresh_functions.php,v 1.31 2008/01/26 23:19:58 nickpalmer Exp $
*
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
@@ -8,7 +8,7 @@
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: refresh_functions.php,v 1.30 2007/12/04 17:42:09 joasch Exp $
+ * $Id: refresh_functions.php,v 1.31 2008/01/26 23:19:58 nickpalmer Exp $
* @author Luis Argerich (lrargerich@yahoo.com)
* @package search
* @subpackage functions
@@ -152,7 +152,7 @@ function rebuild_index($pContentType, $pUnindexedOnly = false) {
global $gBitSystem, $gLibertySystem;
$arguments = array();
$whereClause = "";
- ini_set("max_execution_time", "300");
+ ini_set("max_execution_time", "3000");
if (!$pUnindexedOnly) {
delete_index_content_type($pContentType);
}
diff --git a/search_lib.php b/search_lib.php
index 0fd78ef..e5bda42 100644
--- a/search_lib.php
+++ b/search_lib.php
@@ -1,6 +1,6 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_search/search_lib.php,v 1.36 2007/07/02 08:05:56 lsces Exp $
+ * $Header: /cvsroot/bitweaver/_bit_search/search_lib.php,v 1.37 2008/01/26 23:19:58 nickpalmer Exp $
*
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
@@ -8,7 +8,7 @@
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: search_lib.php,v 1.36 2007/07/02 08:05:56 lsces Exp $
+ * $Id: search_lib.php,v 1.37 2008/01/26 23:19:58 nickpalmer Exp $
* @author Luis Argerich (lrargerich@yahoo.com)
* @package search
*/
@@ -162,7 +162,9 @@ class SearchLib extends BitBase {
$ret = array();
foreach( $gLibertySystem->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}
+ <div class="row">
+ {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}
+ </div>
+ {/foreach}
+
+ <input type="hidden" name="page" value="{$page}" />
+ <div class="row">
+ {formlabel label="Searchable Content"}
+ {forminput}
+ {html_checkboxes options=$formSearchable.guids value=y name=searchable_content separator="<br />" checked=$formSearchable.checked}
+ {formhelp note="Here you can select what content can be searched."}
+ {/forminput}
+ </div>
+
+ <div class="row submit">
+ <input type="submit" name="store_content" value="{tr}Change preferences{/tr}" />
+ </div>
+ {/form}
+
+ {/jstab}
+
{jstab title="Delete / Rebuild Index"}
{formfeedback hash=$feedback}