value="<?php 
echo $words;
?>
" /></td>
	</tr>
	<tr>
		<td><?php 
echo gettext("Search fields:");
?>
</td>
		<td>
		<?php 
echo '<ul class="searchchecklist">' . "\n";
$selected_fields = array();
$engine = new SearchEngine();
$available_fields = $engine->allowedSearchFields();
foreach ($available_fields as $key => $value) {
    if ($value & $fields) {
        $selected_fields[$key] = $value;
    }
}
generateUnorderedListFromArray($selected_fields, $available_fields, '_SEARCH_', false, true, true);
echo '</ul>';
?>
		
		</td>
	</tr>

</table>

<input type="submit" value="<?php 
示例#2
0
        echo gettext("A reminder hint for the password.");
        ?>
										</td>
									</tr>
									<?php 
    }
    ?>
								<tr>
									<td><?php 
    echo gettext("Search behavior settings:");
    ?>
</td>
									<?php 
    $engine = new SearchEngine();
    $fields = $engine->getSearchFieldList();
    $set_fields = $engine->allowedSearchFields();
    $fields = array_diff($fields, $set_fields);
    ?>
								<script>
																					$(function() {
																					$("#resizable").resizable({
																					maxWidth: 350,
																									minWidth: 350, minHeight: 120,
																									resize: function(event, ui) {
																									$('#searchchecklist').height($('#resizable').height());
																									}
																					});
																					});</script>
								<td>
									<?php 
    echo gettext('Fields list:');
/**
 * Prints the search form
 *
 * Search works on a list of tokens entered into the search form.
 *
 * Tokens may be part of boolean expressions using &, |, !, and parens. (Comma is retained as a synonom of | for
 * backwords compatibility.)
 *
 * Tokens may be enclosed in quotation marks to create exact pattern matches or to include the boolean operators and
 * parens as part of the tag..
 *
 * @param string $prevtext text to go before the search form
 * @param string $id css id for the search form, default is 'search'
 * @param string $buttonSource optional path to the image for the button or if not a path to an image,
 * 											this will be the button hint
 * @param string $buttontext optional text for the button ("Search" will be the default text)
 * @param string $iconsource optional theme based icon for the search fields toggle
 * @param array $query_fields override selection for enabled fields with this list
 * @param array $objects_list optional array of things to search eg. [albums]=>[list], etc.
 * 														if the list is simply 0, the objects will be omitted from the search
 * @param string $within set to true to search within current results, false to search fresh
 * @since 1.1.3
 */
function printSearchForm($prevtext = NULL, $id = 'search', $buttonSource = NULL, $buttontext = '', $iconsource = NULL, $query_fields = NULL, $object_list = NULL, $within = NULL)
{
    global $_zp_adminJS_loaded, $_zp_current_search;
    $engine = new SearchEngine();
    if (!is_null($_zp_current_search) && !$_zp_current_search->getSearchWords()) {
        $engine->clearSearchWords();
    }
    if (!is_null($object_list)) {
        if (array_key_exists(0, $object_list)) {
            // handle old form albums list
            trigger_error(gettext('printSearchForm $album_list parameter is deprecated. Pass array("albums"=>array(album, album, ...)) instead.'), E_USER_NOTICE);
            $object_list = array('albums' => $object_list);
        }
    }
    if (empty($buttontext)) {
        $buttontext = gettext("Search");
    }
    $zf = WEBPATH . "/" . ZENFOLDER;
    $searchwords = $engine->codifySearchString();
    if (substr($searchwords, -1, 1) == ',') {
        $searchwords = substr($searchwords, 0, -1);
    }
    if (empty($searchwords)) {
        $within = false;
        $hint = '%s';
    } else {
        $hint = gettext('%s within previous results');
    }
    if (preg_match('!\\/(.*)[\\.png|\\.jpg|\\.jpeg|\\.gif]$!', $buttonSource)) {
        $buttonSource = 'src="' . $buttonSource . '" alt="' . $buttontext . '"';
        $button = 'title="' . sprintf($hint, $buttontext) . '"';
        $type = 'image';
    } else {
        $type = 'submit';
        if ($buttonSource) {
            $button = 'value="' . $buttontext . '" title="' . sprintf($hint, $buttonSource) . '"';
            $buttonSource = '';
        } else {
            $button = 'value="' . $buttontext . '" title="' . sprintf($hint, $buttontext) . '"';
        }
    }
    if (empty($iconsource)) {
        $iconsource = WEBPATH . '/' . ZENFOLDER . '/images/searchfields_icon.png';
    }
    if (is_null($within)) {
        $within = getOption('search_within');
    }
    if (MOD_REWRITE) {
        $searchurl = SEO_WEBPATH . '/' . _SEARCH_ . '/';
    } else {
        $searchurl = WEBPATH . "/index.php?p=search";
    }
    if (!$within) {
        $engine->clearSearchWords();
    }
    $fields = $engine->allowedSearchFields();
    if (!$_zp_adminJS_loaded) {
        $_zp_adminJS_loaded = true;
        ?>
		<script type="text/javascript" src="<?php 
        echo WEBPATH . '/' . ZENFOLDER;
        ?>
/js/admin.js"></script>
		<?php 
    }
    ?>
	<div id="<?php 
    echo $id;
    ?>
">
		<!-- search form -->
		<form method="post" action="<?php 
    echo $searchurl;
    ?>
" id="search_form">
			<script type="text/javascript">
			// <!-- <![CDATA[
			var within = <?php 
    echo (int) $within;
    ?>
;
			function search_(way) {
				within = way;
				if (way) {
					$('#search_submit').attr('title', '<?php 
    echo sprintf($hint, $buttontext);
    ?>
');
				} else {
					lastsearch = '';
					$('#search_submit').attr('title', '<?php 
    echo $buttontext;
    ?>
');
				}
				$('#search_input').val('');
			}
			$('#search_form').submit(function() {
				if (within) {
					var newsearch = $.trim($('#search_input').val());
					if (newsearch.substring(newsearch.length - 1) == ',') {
						newsearch = newsearch.substr(0, newsearch.length - 1);
					}
					if (newsearch.length > 0) {
						$('#search_input').val('(<?php 
    echo $searchwords;
    ?>
) AND (' + newsearch + ')');
					} else {
						$('#search_input').val('<?php 
    echo $searchwords;
    ?>
');
					}
				}
				return true;
			});
    $(document).ready(function() {
      $( $("#checkall_searchfields") ).on( "click", function() {
        $("#searchextrashow :checkbox").prop("checked", $("#checkall_searchfields").prop("checked") );
      });
    });
			// ]]> -->
			</script>
			<?php 
    echo $prevtext;
    ?>
			<div>
				<span class="tagSuggestContainer">
					<input type="text" name="words" value="" id="search_input" size="10" />
				</span>
				<?php 
    if (count($fields) > 1 || $searchwords) {
        ?>
					<a href="javascript:toggle('searchextrashow');" ><img src="<?php 
        echo $iconsource;
        ?>
" title="<?php 
        echo gettext('search options');
        ?>
" alt="<?php 
        echo gettext('fields');
        ?>
" id="searchfields_icon" /></a>
				<?php 
    }
    ?>
				<input type="<?php 
    echo $type;
    ?>
" <?php 
    echo $button;
    ?>
 class="button buttons" id="search_submit" <?php 
    echo $buttonSource;
    ?>
 data-role="none" />
				<?php 
    if (is_array($object_list)) {
        foreach ($object_list as $key => $list) {
            ?>
						<input type="hidden" name="in<?php 
            echo $key;
            ?>
" value="<?php 
            if (is_array($list)) {
                echo html_encode(implode(',', $list));
            } else {
                echo html_encode($list);
            }
            ?>
" />
									 <?php 
        }
    }
    ?>
				<br />
				<?php 
    if (count($fields) > 1 || $searchwords) {
        $fields = array_flip($fields);
        natcasesort($fields);
        $fields = array_flip($fields);
        if (is_null($query_fields)) {
            $query_fields = $engine->parseQueryFields();
        } else {
            if (!is_array($query_fields)) {
                $query_fields = $engine->numericFields($query_fields);
            }
        }
        if (count($query_fields) == 0) {
            $query_fields = $engine->allowedSearchFields();
        }
        ?>
					<div style="display:none;" id="searchextrashow">
						<?php 
        if ($searchwords) {
            ?>
							<label>
								<input type="radio" name="search_within" id="search_within-1" value="1"<?php 
            if ($within) {
                echo ' checked="checked"';
            }
            ?>
 onclick="search_(1);" />
								<?php 
            echo gettext('Within');
            ?>
							</label>
							<label>
								<input type="radio" name="search_within" id="search_within-0" value="1"<?php 
            if (!$within) {
                echo ' checked="checked"';
            }
            ?>
 onclick="search_(0);" />
								<?php 
            echo gettext('New');
            ?>
							</label>
							<?php 
        }
        if (count($fields) > 1) {
            ?>
							<ul>
        <li><label><input type="checkbox" name="checkall_searchfields" id="checkall_searchfields" checked="checked">* <?php 
            echo gettext('Check/uncheck all');
            ?>
 *</label></li>
								<?php 
            foreach ($fields as $display => $key) {
                echo '<li><label><input id="SEARCH_' . $key . '" name="SEARCH_' . $key . '" type="checkbox"';
                if (in_array($key, $query_fields)) {
                    echo ' checked="checked" ';
                }
                echo ' value="' . $key . '"  /> ' . $display . "</label></li>" . "\n";
            }
            ?>
							</ul>
							<?php 
        }
        ?>
					</div>
					<?php 
    }
    ?>
			</div>
		</form>
	</div><!-- end of search form -->
	<?php 
}
/**
 * Prints the search form
 *
 * Search works on a list of tokens entered into the search form.
 *
 * Tokens may be part of boolean expressions using &, |, !, and parens. (Comma is retained as a synonom of | for
 * backwords compatibility.)
 *
 * Tokens may be enclosed in quotation marks to create exact pattern matches or to include the boolean operators and
 * parens as part of the tag..
 *
 * @param string $prevtext text to go before the search form
 * @param string $id css id for the search form, default is 'search'
 * @param string $buttonSource optional path to the image for the button or if not a path to an image,
 * 											this will be the button hint
 * @param string $buttontext optional text for the button ("Search" will be the default text)
 * @param string $iconsource optional theme based icon for the search fields toggle
 * @param array $query_fields override selection for enabled fields with this list
 * @param array $objects_list optional array of things to search eg. [albums]=>[list], etc.
 * 														if the list is simply 0, the objects will be omitted from the search
 * @param string $within set to true to search within current results, false to search fresh
 * @since 1.1.3
 */
function printSearchForm($prevtext = NULL, $id = 'search', $buttonSource = NULL, $buttontext = '', $iconsource = NULL, $query_fields = NULL, $object_list = NULL, $within = NULL)
{
    global $_zp_adminJS_loaded, $_zp_current_search, $_zp_current_album;
    $engine = new SearchEngine();
    if (!is_null($_zp_current_search) && !$_zp_current_search->getSearchWords()) {
        $engine->clearSearchWords();
    }
    if (empty($buttontext)) {
        $buttontext = gettext("Search");
    }
    $zf = WEBPATH . "/" . ZENFOLDER;
    $searchwords = $engine->codifySearchString();
    if (substr($searchwords, -1, 1) == ',') {
        $searchwords = substr($searchwords, 0, -1);
    }
    if (empty($searchwords)) {
        $within = false;
        $hint = '%s';
    } else {
        $hint = gettext('%s within previous results');
    }
    if (preg_match('!\\/(.*)[\\.png|\\.jpg|\\.jpeg|\\.gif]$!', $buttonSource)) {
        $buttonSource = 'src="' . $buttonSource . '" alt="' . $buttontext . '"';
        $button = 'title="' . sprintf($hint, $buttontext) . '"';
        $type = 'image';
    } else {
        $type = 'submit';
        if ($buttonSource) {
            $button = 'value="' . $buttontext . '" title="' . sprintf($hint, $buttonSource) . '"';
            $buttonSource = '';
        } else {
            $button = 'value="' . $buttontext . '" title="' . sprintf($hint, $buttontext) . '"';
        }
    }
    if (empty($iconsource)) {
        $iconsource = WEBPATH . '/' . ZENFOLDER . '/images/searchfields_icon.png';
    }
    if (is_null($within)) {
        $within = getOption('search_within');
    }
    if (MOD_REWRITE) {
        $searchurl = SEO_WEBPATH . '/' . _SEARCH_ . '/';
    } else {
        $searchurl = WEBPATH . "/index.php?p=search";
    }
    if (!$within) {
        $engine->clearSearchWords();
    }
    $fields = $engine->allowedSearchFields();
    if (!$_zp_adminJS_loaded) {
        $_zp_adminJS_loaded = true;
        ?>
		<script type="text/javascript" src="<?php 
        echo WEBPATH . '/' . ZENFOLDER;
        ?>
/js/admin.js"></script>
		<?php 
    }
    ?>
	<div id="<?php 
    echo $id;
    ?>
">
		<!-- search form -->
		<script type="text/javascript">
				// <!-- <![CDATA[
				var within = <?php 
    echo (int) $within;
    ?>
;
				function search_(way) {
					within = way;
					if (way) {
						$('#search_submit').attr('title', '<?php 
    echo sprintf($hint, $buttontext);
    ?>
');
					} else {
						lastsearch = '';
						$('#search_submit').attr('title', '<?php 
    echo $buttontext;
    ?>
');
					}
					$('#search_input').val('');
				}
				$('#search_form').submit(function () {
					if (within) {
						var newsearch = $.trim($('#search_input').val());
						if (newsearch.substring(newsearch.length - 1) == ',') {
							newsearch = newsearch.substr(0, newsearch.length - 1);
						}
						if (newsearch.length > 0) {
							$('#search_input').val('(<?php 
    echo $searchwords;
    ?>
) AND (' + newsearch + ')');
						} else {
							$('#search_input').val('<?php 
    echo $searchwords;
    ?>
');
						}
					}
					return true;
				});
				function search_all() {
					//search all is Copyright 2014 by Stephen L Billard for use in {@link https://github.com/ZenPhoto20/ZenPhoto20 ZenPhoto20}. All rights reserved
					var check = $('#SEARCH_checkall').prop('checked');
					$('.SEARCH_checkall').prop('checked', check);
				}

				// ]]> -->
		</script>
		<form method="post" action="<?php 
    echo $searchurl;
    ?>
" id="search_form">
			<?php 
    echo $prevtext;
    ?>
			<div>
				<span class="tagSuggestContainer">
					<input type="text" name="words" value="" id="search_input" size="10" />
				</span>
				<?php 
    if (count($fields) > 1 || $searchwords) {
        ?>
					<a onclick="toggle('searchextrashow');" ><img src="<?php 
        echo $iconsource;
        ?>
" title="<?php 
        echo gettext('search options');
        ?>
" alt="<?php 
        echo gettext('fields');
        ?>
" id="searchfields_icon" /></a>
				<?php 
    }
    ?>
				<input type="<?php 
    echo $type;
    ?>
" <?php 
    echo $button;
    ?>
 class="button buttons" id="search_submit" <?php 
    echo $buttonSource;
    ?>
 data-role="none" />
				<?php 
    if (is_array($object_list)) {
        foreach ($object_list as $key => $list) {
            if (is_array($list)) {
                if ($key == 'albums' && count($list) == 1 && $_zp_current_album && $_zp_current_album->name == end($list)) {
                    // special case for current album, search its offspring
                    $list = array_merge($list, $_zp_current_album->getOffspring());
                }
                $list = implode(',', $list);
            }
            ?>
						<input type="hidden" name="in<?php 
            echo $key;
            ?>
" value="<?php 
            echo html_encode($list);
            ?>
" />
						<?php 
        }
    }
    ?>
				<br />
				<?php 
    if (count($fields) > 1 || $searchwords) {
        if (is_null($query_fields)) {
            $query_fields = $engine->parseQueryFields();
        } else {
            if (!is_array($query_fields)) {
                $query_fields = $engine->numericFields($query_fields);
            }
        }
        if (count($query_fields) == 0) {
            $query_fields = $engine->allowedSearchFields();
        }
        ?>
					<div style="display:none;" id="searchextrashow">
						<?php 
        if ($searchwords) {
            ?>
							<label>
								<input type="radio" name="search_within" id="search_within-1" value="1"<?php 
            if ($within) {
                echo ' checked="checked"';
            }
            ?>
 onclick="search_(1);" />
								<?php 
            echo gettext('Within');
            ?>
							</label>
							<label>
								<input type="radio" name="search_within" id="search_within-0" value="1"<?php 
            if (!$within) {
                echo ' checked="checked"';
            }
            ?>
 onclick="search_(0);" />
								<?php 
            echo gettext('New');
            ?>
							</label>
							<?php 
        }
        if (count($fields) > 1) {
            ?>
							<ul>
								<?php 
            echo gettext('All');
            ?>
 <input type="checkbox" id="SEARCH_checkall" checked="checked" onclick="search_all();" />
								<?php 
            foreach ($fields as $display => $key) {
                echo '<li><label><input class="SEARCH_checkall" id="SEARCH_' . $key . '" name="SEARCH_' . $key . '" type="checkbox"';
                if (in_array($key, $query_fields)) {
                    echo ' checked="checked" ';
                }
                echo ' value="' . $key . '"  /> ' . trim($display, ':') . "</label></li>" . "\n";
            }
            ?>
							</ul>
							<?php 
        }
        ?>
					</div>
					<?php 
    }
    ?>
			</div>
		</form>
	</div><!-- end of search form -->
	<?php 
}
/**
* Prints the search form
*
* Search works on a list of tokens entered into the search form.
*
* Tokens may be part of boolean expressions using &, |, !, and parens. (Comma is retained as a synonom of | for
* backwords compatibility.)
*
* Tokens may be enclosed in quotation marks to create exact pattern matches or to include the boolean operators and
* parens as part of the tag..
*
* @param string $prevtext text to go before the search form
* @param string $id css id for the search form, default is 'search'
* @param string $buttonSource optional path to the image for the button
* @param string $buttontext optional text for the button ("Search" will be the default text)
* @param string $iconsource optional theme based icon for the search fields toggle
* @param array $query_fields override selection for enabled fields with this list
* @param array $objects_list optional array of things to search eg. [albums]=>[list], etc.
* 														if the list is simply 0, the objects will be omitted from the search
* @param string $reseticonsource optional theme based icon for reset search icon
* @since 1.1.3
*/
function printSearchForm($prevtext = NULL, $id = 'search', $buttonSource = NULL, $buttontext = '', $iconsource = NULL, $query_fields = NULL, $object_list = NULL, $reseticonsource = NULL)
{
    global $_zp_adminJS_loaded;
    if (!is_null($object_list)) {
        if (array_key_exists(0, $object_list)) {
            // handle old form albums list
            trigger_error(gettext('printSearchForm $album_list parameter is deprecated. Pass array("albums"=>array(album, album, ...)) instead.'), E_USER_NOTICE);
            $object_list = array('albums' => $object_list);
        }
    }
    if (empty($buttontext)) {
        $buttontext = gettext("Search");
    } else {
        $buttontext = sanitize($buttontext);
    }
    $zf = WEBPATH . "/" . ZENFOLDER;
    $searchwords = getSearchWords();
    if (substr($searchwords, -1, 1) == ',') {
        $searchwords = substr($searchwords, 0, -1);
    }
    if (empty($searchwords)) {
        $hint = '%s';
    } else {
        $hint = gettext('%s within previous results');
    }
    if (empty($buttonSource)) {
        $type = 'submit';
        $button = 'value="' . $buttontext . '" title="' . sprintf($hint, $buttontext) . '"';
    } else {
        $buttonSource = 'src="' . $buttonSource . '" alt="' . $buttontext . '"';
        $button = 'title="' . sprintf($hint, $buttontext) . '"';
        $type = 'image';
    }
    if (empty($iconsource)) {
        $iconsource = WEBPATH . '/' . ZENFOLDER . '/images/searchfields_icon.png';
    }
    if (empty($reseticonsource)) {
        $reseticonsource = WEBPATH . '/' . ZENFOLDER . '/images/reset_icon.png';
    }
    if (MOD_REWRITE) {
        $searchurl = '/page/search/';
    } else {
        $searchurl = "/index.php?p=search";
    }
    $engine = new SearchEngine();
    $fields = $engine->allowedSearchFields();
    if (!$_zp_adminJS_loaded) {
        $_zp_adminJS_loaded = true;
        ?>
		<script type="text/javascript" src="<?php 
        echo WEBPATH . '/' . ZENFOLDER;
        ?>
/js/admin.js"></script>
		<?php 
    }
    ?>
	<div id="<?php 
    echo $id;
    ?>
"><!-- search form -->

		<form method="post" action="<?php 
    echo WEBPATH . $searchurl;
    ?>
" id="search_form">
			<script type="text/javascript">
				// <!-- <![CDATA[
				function reset_search() {
					lastsearch='';
					$('#reset_search').hide();
					$('#search_submit').attr('title', '<?php 
    echo $buttontext;
    ?>
');
					$('#search_input').val('');
				}
				var lastsearch = '<?php 
    echo addslashes(html_entity_decode(addslashes($searchwords)));
    ?>
';
				var savedlastsearch = lastsearch;
				$('#search_form').submit(function(){
					if (lastsearch) {
						var newsearch = $.trim($('#search_input').val());
						if (newsearch.substring(newsearch.length - 1)==',') {
							newsearch = newsearch.substr(0,newsearch.length-1);
						}
						if (newsearch.length > 0) {
							$('#search_input').val('('+lastsearch+') AND ('+newsearch+')');
						} else {
							$('#search_input').val(lastsearch);
						}
					}
					return true;
				});
				// ]]> -->
			</script>
			<?php 
    echo $prevtext;
    ?>
			<input type="text" name="words" value="" id="search_input" size="10" />
			<?php 
    if (count($fields) > 1) {
        ?>
				<a href="javascript:toggle('searchextrashow');" ><img src="<?php 
        echo $iconsource;
        ?>
" title="<?php 
        echo gettext('select search fields');
        ?>
" alt="<?php 
        echo gettext('fields');
        ?>
" id="searchfields_icon" /></a>
			<?php 
    }
    ?>
			<span style="white-space:nowrap;display:<?php 
    if ($searchwords) {
        echo 'inline';
    } else {
        echo 'none';
    }
    ?>
" id="reset_search"><a href="javascript:reset_search();" title="<?php 
    echo gettext('Clear search');
    ?>
"><img src="<?php 
    echo $reseticonsource;
    ?>
" alt="<?php 
    echo gettext('Reset search');
    ?>
" /></a></span>
			<input type="<?php 
    echo $type;
    ?>
" <?php 
    echo $button;
    ?>
 class="pushbutton" id="search_submit" <?php 
    echo $buttonSource;
    ?>
 />
			<?php 
    if (is_array($object_list)) {
        foreach ($object_list as $key => $list) {
            ?>
					<input type="hidden" name="in<?php 
            echo $key;
            ?>
" value="<?php 
            if (is_array($list)) {
                echo html_encode(implode(',', $list));
            } else {
                echo html_encode($list);
            }
            ?>
" />
					<?php 
        }
    }
    ?>
			<br />
			<?php 
    if (count($fields) > 1) {
        $fields = array_flip($fields);
        natcasesort($fields);
        $fields = array_flip($fields);
        if (is_null($query_fields)) {
            $query_fields = $engine->parseQueryFields();
        } else {
            if (!is_array($query_fields)) {
                $query_fields = $engine->numericFields($query_fields);
            }
        }
        if (count($query_fields) == 0) {
            $query_fields = $engine->allowedSearchFields();
        }
        ?>
				<ul style="display:none;" id="searchextrashow">
				<?php 
        foreach ($fields as $display => $key) {
            echo '<li><label><input id="SEARCH_' . $key . '" name="SEARCH_' . $key . '" type="checkbox"';
            if (in_array($key, $query_fields)) {
                echo ' checked="checked" ';
            }
            echo ' value="' . $key . '"  /> ' . $display . "</label></li>" . "\n";
        }
        ?>
				</ul>
				<?php 
    }
    ?>
		</form>
	</div><!-- end of search form -->
	<?php 
}
/**
 * Prints the search form
 *
 * Search works on a list of tokens entered into the search form.
 *
 * Tokens may be part of boolean expressions using &, |, !, and parens. (Comma is retained as a synonom of | for
 * backwords compatibility.) If tokens are separated by spaces, the OR function is presumed.
 *
 * Tokens may be enclosed in quotation marks to create exact pattern matches or to include the boolean operators and
 * parens as part of the tag..
 *
 * @param string $prevtext text to go before the search form
 * @param string $id css id for the search form, default is 'search'
 * @param string $buttonSource optional path to the image for the button
 * @param string $buttontext optional text for the button ("Search" will be the default text)
 * @param string $iconsource optional theme based icon for the search fields toggle
 * @since 1.1.3
 */
function printSearchForm($prevtext = NULL, $id = 'search', $buttonSource = NULL, $buttontext = '', $iconsource = NULL)
{
    global $_zp_adminJS_loaded;
    if (empty($buttontext)) {
        $buttontext = gettext("Search");
    } else {
        $buttontext = sanitize($buttontext);
    }
    if (checkforPassword(true)) {
        return;
    }
    $zf = WEBPATH . "/" . ZENFOLDER;
    $dataid = $id . '_data';
    $searchwords = isset($_POST['words']) ? html_encode(sanitize($_REQUEST['words'], 0), false) : '';
    $fields = getOption('search_fields');
    if (empty($buttonSource)) {
        $type = 'submit';
    } else {
        $buttonSource = 'src="' . $buttonSource . '" alt="' . $buttontext . '"';
        $type = 'image';
    }
    if (empty($iconsource)) {
        $iconsource = WEBPATH . '/' . ZENFOLDER . '/images/searchfields_icon.png';
    }
    if (getOption('mod_rewrite')) {
        $searchurl = '/page/search/';
    } else {
        $searchurl = "/index.php?p=search";
    }
    $engine = new SearchEngine();
    $fields = array_flip($engine->allowedSearchFields());
    if (!$_zp_adminJS_loaded) {
        $_zp_adminJS_loaded = true;
        ?>
		<script type="text/javascript" src="<?php 
        echo WEBPATH . '/' . ZENFOLDER;
        ?>
/js/admin.js"></script>
	<?php 
    }
    ?>
	<div id="search"><!-- search form -->

	<form method="post" action="<?php 
    echo WEBPATH . $searchurl;
    ?>
" id="search_form">
	<?php 
    echo $prevtext;
    ?>
	<input type="text" name="words" value="<?php 
    echo $searchwords;
    ?>
" id="search_input" size="10" />
	<?php 
    if (count($fields) > 1) {
        ?>
		<a href="javascript: toggle('searchextrashow');"><img src="<?php 
        echo $iconsource;
        ?>
" alt="<?php 
        echo gettext('select search fields');
        ?>
" id="searchfields_icon" /></a>
	<?php 
    }
    ?>
	<input type="<?php 
    echo $type;
    ?>
" value="<?php 
    echo $buttontext;
    ?>
" class="pushbutton" id="search_submit" <?php 
    echo $buttonSource;
    ?>
 />
	<br />
	<?php 
    if (count($fields) > 1) {
        natcasesort($fields);
        $fields = array_flip($fields);
        $query_fields = $engine->parseQueryFields();
        ?>
		<ul style="display:none;" id="searchextrashow">
		<?php 
        foreach ($fields as $key => $item) {
            echo '<li><label for="_SEARCH_' . $item . '"><input id="_SEARCH_' . $item . '" name="_SEARCH_' . $item . '" type="checkbox"';
            if ($item & $query_fields) {
                echo ' checked="checked" ';
            }
            echo ' value="' . $item . '"  /> ' . $key . "</label></li>" . "\n";
        }
        ?>
		</ul>
		<?php 
    }
    ?>
	</form>
	</div><!-- end of search form -->
	<?php 
}
示例#7
0
 /**
  *
  * This method establishes the current set of database fields. It will add the
  * fields to the database if they are not already present. Fields from previous
  * constructor calls that are no longer in the list will be removed from the
  * database (along with any data associated with them.)
  *
  * @param array $newfields
  */
 function constructor($me, $newfields)
 {
     $database = array();
     foreach (getDBTables() as $table) {
         $tablecols = db_list_fields($table);
         foreach ($tablecols as $key => $datum) {
             $database[$table][$datum['Field']] = $datum;
         }
     }
     $current = $fields = $searchDefault = array();
     if (extensionEnabled($me)) {
         //need to update the database tables.
         foreach ($newfields as $newfield) {
             $table = $newfield['table'];
             $name = $newfield['name'];
             if (!($existng = isset($database[$table][$name]))) {
                 if (isset($newfield['searchDefault']) && $newfield['searchDefault']) {
                     $searchDefault[] = $name;
                 }
             }
             if (is_null($newfield['type'])) {
                 if ($name == 'tags') {
                     setOption('adminTagsTab', 1);
                 }
             } else {
                 switch (strtolower($newfield['type'])) {
                     default:
                         $dbType = strtoupper($newfield['type']);
                         break;
                     case 'int':
                         $dbType = strtoupper($newfield['type']) . '(' . min(255, $newfield['size']) . ')';
                         if (isset($newfield['attribute'])) {
                             $dbType .= ' ' . $newfield['attribute'];
                             unset($newfield['attribute']);
                         }
                         break;
                     case 'varchar':
                         $dbType = strtoupper($newfield['type']) . '(' . min(255, $newfield['size']) . ')';
                         break;
                 }
                 if ($existng) {
                     if (strtoupper($database[$table][$name]['Type']) != $dbType || empty($database[$table][$name]['Comment'])) {
                         $cmd = ' CHANGE `' . $name . '`';
                     } else {
                         $cmd = NULL;
                     }
                     unset($database[$table][$name]);
                 } else {
                     $cmd = ' ADD COLUMN';
                 }
                 $sql = 'ALTER TABLE ' . prefix($newfield['table']) . $cmd . ' `' . $name . '` ' . $dbType;
                 if (isset($newfield['attribute'])) {
                     $sql .= ' ' . $newfield['attribute'];
                 }
                 if (isset($newfield['default'])) {
                     $sql .= ' DEFAULT ' . $newfield['default'];
                 }
                 $sql .= " COMMENT 'optional_{$me}'";
                 if ((!$cmd || setupQuery($sql)) && in_array($newfield['table'], array('albums', 'images', 'news', 'news_categories', 'pages'))) {
                     $fields[] = strtolower($newfield['name']);
                 }
                 $current[$newfield['table']][$newfield['name']] = $dbType;
             }
         }
         setOption(get_class($this) . '_addedFields', serialize($current));
         if (!empty($searchDefault)) {
             $fieldExtenderMutex = new zpMutex('fE');
             $fieldExtenderMutex->lock();
             $engine = new SearchEngine();
             $set_fields = $engine->allowedSearchFields();
             $set_fields = array_unique(array_merge($set_fields, $searchDefault));
             setOption('search_fields', implode(',', $set_fields));
             $fieldExtenderMutex->unlock();
         }
     } else {
         purgeOption(get_class($this) . '_addedFields');
     }
     foreach ($database as $table => $fields) {
         //drop fields no longer defined
         foreach ($fields as $field => $orphaned) {
             if ($orphaned['Comment'] == "optional_{$me}") {
                 $sql = 'ALTER TABLE ' . prefix($table) . ' DROP `' . $field . '`';
                 setupQuery($sql);
             }
         }
     }
 }