Пример #1
0
/**
 * 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 
}
printTabs();
echo "\n" . '<div id="content">';
zp_apply_filter('admin_note', 'albums', 'dynamic');
echo "<h1>" . gettext("zenphoto Create Dynamic Album") . "</h1>\n";
if (isset($_POST['savealbum'])) {
    // we fell through, some kind of error
    echo "<div class=\"errorbox space\">";
    echo "<h2>" . gettext("Failed to save the album file") . "</h2>";
    echo "</div>\n";
}
$albumlist = array();
genAlbumUploadList($albumlist);
$params = trim(zp_getCookie('zenphoto_search_params'));
$search->setSearchParams($params);
$fields = $search->fieldList;
$albumname = $words = $search->codifySearchString();
$images = $search->getImages(0);
foreach ($images as $image) {
    $folder = $image['folder'];
    $filename = $image['filename'];
    $imagelist[] = '/' . $folder . '/' . $filename;
}
$subalbums = $search->getAlbums(0);
foreach ($subalbums as $folder) {
    getSubalbumImages($folder);
}
$albumname = sanitize_path($albumname);
$albumname = seoFriendly($albumname);
$old = '';
while ($old != $albumname) {
    $old = $albumname;
Пример #3
0
echo "\n" . '<div id="main">';
printTabs();
echo "\n" . '<div id="content">';
zp_apply_filter('admin_note', 'albums', 'dynamic');
echo "<h1>" . gettext("Create Dynamic Album") . "</h1>\n";
if (isset($_POST['savealbum'])) {
    // we fell through, some kind of error
    echo "<div class=\"errorbox space\">";
    echo "<h2>" . gettext("Failed to save the album file") . "</h2>";
    echo "</div>\n";
}
$albumlist = array();
genAlbumList($albumlist);
$fields = $search->fieldList;
$albumname = $search->getSearchWords();
$words = $search->codifySearchString();
$images = $search->getImages(0);
foreach ($images as $image) {
    $folder = $image['folder'];
    $filename = $image['filename'];
    $imagelist[] = '/' . $folder . '/' . $filename;
}
$subalbums = $search->getAlbums(0);
foreach ($subalbums as $folder) {
    getSubalbumImages($folder);
}
$albumname = sanitize_path($albumname);
$albumname = seoFriendly($albumname);
$old = '';
while ($old != $albumname) {
    $old = $albumname;
Пример #4
0
/**
 * 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 
}