X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsearch.php;h=7e037d223a019898a7ca92f5ee249c599a410dc8;hb=5049218e0ffd062bc72c44483740a23b2f261464;hp=aa7ff0b367f70d0ca978f17c09f2384c9c117a6e;hpb=5c4ff7bfc6e04337bd6bcf76743b1fbb92556233;p=squirrelmail.git
diff --git a/src/search.php b/src/search.php
index aa7ff0b3..7e037d22 100644
--- a/src/search.php
+++ b/src/search.php
@@ -14,24 +14,23 @@
* @package squirrelmail
* @subpackage search
* @link http://www.ietf.org/rfc/rfc3501.txt
+ * @todo explain why references are used in function calls
*/
/**
- * Path for SquirrelMail required files.
- * @ignore
+ * Include the SquirrelMail initialization file.
*/
-define('SM_PATH','../');
+require('../include/init.php');
/** SquirrelMail required files.
*/
-include_once(SM_PATH . 'include/validate.php');
-include_once(SM_PATH . 'functions/strings.php');
-include_once(SM_PATH . 'functions/imap_asearch.php');
-include_once(SM_PATH . 'functions/imap_mailbox.php');
-include_once(SM_PATH . 'functions/imap_messages.php');
-include_once(SM_PATH . 'functions/mime.php');
-include_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()...
-include_once(SM_PATH . 'class/template/template.class.php');
+require_once(SM_PATH . 'functions/imap_asearch.php');
+require_once(SM_PATH . 'functions/imap_messages.php');
+require_once(SM_PATH . 'functions/imap_general.php');
+require_once(SM_PATH . 'functions/mime.php');
+require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()
+require_once(SM_PATH . 'functions/forms.php');
+require_once(SM_PATH . 'functions/date.php');
/** Prefs array ordinals. Must match $recent_prefkeys and $saved_prefkeys
*/
@@ -48,97 +47,42 @@ define('ASEARCH_MAX', 7);
*/
define('ASEARCH_CRITERIA', 'criteria');
-/** Builds a href with params
- * @param string $params optional parameters to GET
- */
-function asearch_get_href($params = '')
-{
- $href = 'search.php';
- if ($params != '')
- $href .= '?' . $params;
- return $href;
-}
-
-/** Builds a [link]
- * @param string $href (reference)
- * @param string $text
- * @param string $title
- */
-function asearch_get_link(&$href, $text, $title = '')
-{
- if ($title != '')
- $title = ' title="' . $title . '"';
- return '' . $text . '';
-}
-
-/** Builds a toggle [link]
- * @param integer $value
- * @param string $action
- * @param array $text_array
- * @param array $title_array
- */
-function asearch_get_toggle_link($value, $action, $text_array, $title_array = array())
-{
- $asearch_nz=asearch_nz($title_array[$value]);
- $asearch_get_href=asearch_get_href($action . '=' . (int)$value);
- return asearch_get_link($asearch_get_href, $text_array[$value], $asearch_nz);
-}
/**
+ * Array sort callback used to sort $imap_asearch_options
* @param string $a
* @param string $b
* @return bool strcoll()-like result
+ * @since 1.5.0
+ * @private
*/
function asearch_unhtml_strcoll($a, $b)
{
+ // FIXME: Translation policy says "no html entities in translations"
return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b));
}
-
-/**
- * @param string $mailbox mailbox name utf7 encoded inc. special case INBOX
- * @return string mailbox name ready to display (utf7 decoded or localized INBOX)
- */
-function imap_get_mailbox_display($mailbox)
-{
- if (strtoupper($mailbox) == 'INBOX')
- return _("INBOX");
- return imap_utf7_decode_local($mailbox);
-}
-
/**
* @param string $mailbox mailbox name or special case 'All Folders'
* @return string mailbox name ready to display (utf7 decoded or localized 'All Folders')
+ * @since 1.5.0
+ * @private
*/
function asearch_get_mailbox_display($mailbox)
{
- if ($mailbox == 'All Folders')
+ if ($mailbox == 'All Folders') {
return _("All Folders");
- return imap_get_mailbox_display($mailbox);
-}
-
-/**
- * @param array $color color array
- * @param string $txt text to display
- * @return string title ready to display
- */
-function asearch_get_title_display(&$color, $txt)
-{
- return '' . $txt . '';
-}
-/**
- * @param array $color color array
- * @param string $txt text to display
- * @return string error text ready to display
- */
-function asearch_get_error_display(&$color, $txt)
-{
- return '' . '' . $txt . '';
+ } elseif (strtoupper($mailbox) == 'INBOX') {
+ return _("INBOX");
+ }
+ return imap_utf7_decode_local($mailbox);
}
/**
* @param array $input_array array to serialize
* @return string a string containing a byte-stream representation of value that can be stored anywhere
+ * @since 1.5.0
+ * @private
*/
function asearch_serialize(&$input_array)
{
@@ -151,6 +95,8 @@ function asearch_serialize(&$input_array)
/**
* @param string $input_string string to unserialize
* @return array
+ * @since 1.5.0
+ * @private
*/
function asearch_unserialize($input_string)
{
@@ -161,10 +107,15 @@ function asearch_unserialize($input_string)
}
/**
+ * Gets user's advanced search preferences
+ *
+ * Arguments are different in 1.5.0.
* @param string $key the pref key
* @param integer $index the pref key index
* @param string $default default value
* @return string pref value
+ * @since 1.5.0
+ * @private
*/
function asearch_getPref(&$key, $index, $default = '')
{
@@ -173,10 +124,15 @@ function asearch_getPref(&$key, $index, $default = '')
}
/**
+ * Sets user's advanced search preferences
+ *
+ * Arguments are different in 1.5.0.
* @param string $key the pref key
* @param integer $index the pref key index
* @param string $value pref value to set
* @return bool status
+ * @since 1.5.0
+ * @private
*/
function asearch_setPref(&$key, $index, $value)
{
@@ -185,9 +141,14 @@ function asearch_setPref(&$key, $index, $value)
}
/**
+ * Deletes user's advanced search preferences
+ *
+ * Arguments are different in 1.5.0.
* @param string $key the pref key
* @param integer $index the pref key index
* @return bool status
+ * @since 1.5.0
+ * @private
*/
function asearch_removePref(&$key, $index)
{
@@ -195,7 +156,14 @@ function asearch_removePref(&$key, $index)
return removePref($data_dir, $username, $key . ($index + !$search_advanced));
}
-/** Sanity checks, done before running the imap command and before calling push_recent
+/**
+ * Sanity checks, done before running the imap command and before calling push_recent
+ * @param array $where_array search location data
+ * @param array $what_array search criteria data
+ * @param array $exclude_array excluded criteria data
+ * @return string error message or empty string
+ * @since 1.5.0
+ * @private
*/
function asearch_check_query(&$where_array, &$what_array, &$exclude_array)
{
@@ -214,7 +182,13 @@ function asearch_check_query(&$where_array, &$what_array, &$exclude_array)
return '';
}
-/** Read the recent searches from the prefs
+/**
+ * Read the recent searches from the prefs
+ *
+ * Function arguments are different in 1.5.0
+ * @return array recent searches
+ * @since 1.5.0
+ * @private
*/
function asearch_read_recent()
{
@@ -240,7 +214,13 @@ function asearch_read_recent()
return $recent_array;
}
-/** Read the saved searches from the prefs
+/**
+ * Read the saved searches from the prefs
+ *
+ * Function arguments are different in 1.5.0
+ * @return array saved searches
+ * @since 1.5.0
+ * @private
*/
function asearch_read_saved()
{
@@ -261,14 +241,24 @@ function asearch_read_saved()
return $saved_array;
}
-/** Save a recent search to the prefs
+/**
+ * Save a recent search to the prefs
+ *
+ * Function arguments are different in 1.5.0
+ * @param integer $recent_index
+ * @since 1.5.0
+ * @private
*/
function asearch_save_recent($recent_index)
{
global $recent_prefkeys, $saved_prefkeys;
$saved_array = asearch_read_saved();
- $saved_index = count($saved_array[$saved_prefkeys[0]]);
+ if (isset($saved_array[$saved_prefkeys[0]])) {
+ $saved_index = count($saved_array[$saved_prefkeys[0]]);
+ } else {
+ $saved_index = 0;
+ }
$recent_array = asearch_read_recent();
$n = 0;
foreach ($recent_prefkeys as $key) {
@@ -281,7 +271,13 @@ function asearch_save_recent($recent_index)
}
}
-/** Write a recent search to prefs
+/**
+ * Write a recent search to prefs
+ *
+ * Function arguments are different in 1.5.0
+ * @param array $recent_array
+ * @since 1.5.0
+ * @private
*/
function asearch_write_recent(&$recent_array)
{
@@ -300,7 +296,13 @@ function asearch_write_recent(&$recent_array)
}
}
-/** Remove a recent search from prefs
+/**
+ * Remove a recent search from prefs
+ *
+ * Function arguments are different in 1.5.0
+ * @param integer $forget_index removed search number
+ * @since 1.5.0
+ * @private
*/
function asearch_forget_recent($forget_index)
{
@@ -313,7 +315,19 @@ function asearch_forget_recent($forget_index)
asearch_write_recent($recent_array);
}
-/** Find a recent search in the prefs (used to avoid saving duplicates)
+/**
+ * Find a recent search in the prefs (used to avoid saving duplicates)
+ * @param array $recent_array
+ * @param array $mailbox_array
+ * @param array $biop_array
+ * @param array $unop_array
+ * @param array $where_array
+ * @param array $what_array
+ * @param array $exclude_array
+ * @param array $sub_array
+ * @return integer
+ * @since 1.5.0
+ * @private
*/
function asearch_find_recent(&$recent_array, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
{
@@ -347,7 +361,18 @@ function asearch_find_recent(&$recent_array, &$mailbox_array, &$biop_array, &$un
return -1;
}
-/** Push a recent search into the prefs
+/**
+ * Push a recent search into the prefs
+ * @param array $recent_array
+ * @param array $mailbox_array
+ * @param array $biop_array
+ * @param array $unop_array
+ * @param array $where_array
+ * @param array $what_array
+ * @param array $exclude_array
+ * @param array $sub_array
+ * @since 1.5.0
+ * @private
*/
function asearch_push_recent(&$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
{
@@ -378,8 +403,14 @@ function asearch_push_recent(&$mailbox_array, &$biop_array, &$unop_array, &$wher
}
}
-/** Edit a recent search
+/**
+ * Edit a recent search
+ *
+ * Function arguments are different in 1.5.0
* @global array mailbox_array searched mailboxes
+ * @param mixed $index
+ * @since 1.5.0
+ * @private
*/
function asearch_edit_recent($index)
{
@@ -398,8 +429,14 @@ function asearch_edit_recent($index)
}
}
-/** Get last search criteria from session or prefs
- * FIX ME, try to avoid globals
+/**
+ * Get last search criteria from session or prefs
+ *
+ * Function arguments are different in 1.5.0
+ * FIXME, try to avoid globals
+ * @param mixed $index
+ * @since 1.5.0
+ * @private
*/
function asearch_edit_last($index) {
if (sqGetGlobalVar(ASEARCH_CRITERIA, $criteria, SQ_SESSION)) {
@@ -422,7 +459,13 @@ function asearch_edit_last($index) {
}
}
-/** Edit a saved search
+/**
+ * Edit a saved search
+ *
+ * Function arguments are different in 1.5.0
+ * @param mixed $index
+ * @since 1.5.0
+ * @private
*/
function asearch_edit_saved($index)
{
@@ -441,7 +484,13 @@ function asearch_edit_saved($index)
}
}
-/** Write a saved search to the prefs
+/**
+ * Write a saved search to the prefs
+ *
+ * Function arguments are different in 1.5.0
+ * @param array $saved_array
+ * @since 1.5.0
+ * @private
*/
function asearch_write_saved(&$saved_array)
{
@@ -458,7 +507,13 @@ function asearch_write_saved(&$saved_array)
}
}
-/** Delete a saved search from the prefs
+/**
+ * Delete a saved search from the prefs
+ *
+ * Function arguments are different in 1.5.0
+ * @param integer $saved_index
+ * @since 1.5.0
+ * @private
*/
function asearch_delete_saved($saved_index)
{
@@ -474,7 +529,10 @@ function asearch_delete_saved($saved_index)
/** Translate the input date to imap date to local date display,
* so the user can know if the date is wrong or illegal
+ * @param string $what date string
* @return string locally formatted date or error text
+ * @since 1.5.0
+ * @private
*/
function asearch_get_date_display(&$what)
{
@@ -488,8 +546,19 @@ function asearch_get_date_display(&$what)
return _("(Wrong date)");
}
-/** Translate the query to rough natural display
+/**
+ * Translate the query to rough natural display
+ * @param array $color
+ * @param array $mailbox_array
+ * @param array $biop_array
+ * @param array $unop_array
+ * @param array $where_array
+ * @param array $what_array
+ * @param array $exclude_array
+ * @param array $sub_array
* @return string rough natural query ready to display
+ * @since 1.5.0
+ * @private
*/
function asearch_get_query_display(&$color, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array)
{
@@ -507,7 +576,7 @@ function asearch_get_query_display(&$color, &$mailbox_array, &$biop_array, &$uno
$cur_mailbox = 'INBOX';
$biop = asearch_nz($biop_array[$crit_num]);
if (($query_display == '') || ($cur_mailbox != $last_mailbox)) {
- $mailbox_display = ' ' . htmlspecialchars(asearch_get_mailbox_display($cur_mailbox)) . '';
+ $mailbox_display = ' ' . htmlspecialchars(asearch_get_mailbox_display($cur_mailbox)) . '';
if ($query_display == '')
$biop_display = _("In");
else
@@ -528,25 +597,25 @@ function asearch_get_query_display(&$color, &$mailbox_array, &$biop_array, &$uno
$what = $what_array[$crit_num];
if ($what_type) { /* Check opcode parameter */
if ($what == '')
- $what_display = ' ' . asearch_get_error_display($color, _("(Missing argument)"));
+ $what_display = ' ' . _("(Missing argument)") .'';
else {
if ($what_type == 'adate')
$what_display = asearch_get_date_display($what);
else
$what_display = htmlspecialchars($what);
- $what_display = ' ' . $what_display . '';
+ $what_display = ' ' . $what_display . '';
}
}
else {
if ($what)
- $what_display = ' ' . asearch_get_error_display($color, _("(Spurious argument)"));
+ $what_display = ' ' . _("(Spurious argument)") .'';
else
$what_display = '';
}
if ($mailbox_display != '')
- $query_display .= ' ' . $biop_display . '' . $mailbox_display . ' ' . $where_display . '' . $what_display;
+ $query_display .= ' ' . $biop_display . '' . $mailbox_display . ' ' . $where_display . '' . $what_display;
else
- $query_display .= ' ' . $biop_display . ' ' . $where_display . '' . $what_display;
+ $query_display .= ' ' . $biop_display . ' ' . $where_display . '' . $what_display;
}
}
return $query_display;
@@ -572,83 +641,72 @@ function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
'" style="padding: 0px; margin: 0px" />';
}
-
-/** Handle the alternate row colors
- * @return string color value
- */
-function asearch_get_row_color(&$color, $row_num)
-{
-/*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/
- $color_string = $color[4];
- if ($GLOBALS['alt_index_colors']) {
- if (($row_num % 2) == 0) {
- if (!isset($color[12]))
- $color[12] = '#EAEAEA';
- $color_string = $color[12];
- }
- }
- return $color_string;
-}
-
-/** Print a whole query array, recent or saved
+/**
+ * Print a whole query array, recent or saved
+ *
+ * Function arguments are different in 1.5.0
+ * @param array $boxes (unused)
+ * @param array $query_array
+ * @param mixed $query_keys
+ * @param array $action_array
+ * @param mixed $title
+ * @param string $show_pref
+ * @since 1.5.0
+ * @private
*/
function asearch_print_query_array(&$boxes, &$query_array, &$query_keys, &$action_array, $title, $show_pref)
{
- global $color;
global $data_dir, $username;
- global $use_icons, $icon_theme;
+ global $icon_theme_path;
+ global $oTemplate;
$show_flag = getPref($data_dir, $username, $show_pref, 0) & 1;
- $use_icons_flag = ($use_icons) && ($icon_theme != 'none');
- if ($use_icons_flag)
- $text_array = array('',
- '');
- else
- $text_array = array('-', '+');
- $toggle_link = asearch_get_toggle_link(!$show_flag, $show_pref, $text_array, array(_("Fold"), _("Unfold")));
- if (!$use_icons_flag)
- $toggle_link = '[' . $toggle_link . ']';
-
- echo "
\n";
- echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"');
- echo html_tag('tr',
- html_tag('td', $toggle_link, 'center', $color[5], 'width="5%"')
- . html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=4'));
- if ($show_flag) {
- $main_key = $query_keys[ASEARCH_WHERE];
- $query_count = count($query_array[$main_key]);
- for ($query_num = 0, $row_num = 0; $query_num < $query_count; $query_num++) {
- if (!empty($query_array[$main_key][$query_num])) {
- echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num));
-
- unset($search_array);
- foreach ($query_keys as $query_key) {
- $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]);
- }
- $where_array = $search_array[ASEARCH_WHERE];
- $mailbox_array = $search_array[ASEARCH_MAILBOX];
- $what_array = $search_array[ASEARCH_WHAT];
- $unop_array = $search_array[ASEARCH_UNOP];
- $biop_array = asearch_nz($search_array[ASEARCH_BIOP], array());
- $exclude_array = asearch_nz($search_array[ASEARCH_EXCLUDE], array());
- $sub_array = asearch_nz($search_array[ASEARCH_SUB], array());
- $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
-
- echo html_tag('td', $query_num + 1, 'right');
- echo html_tag('td', $query_display, 'center', '', 'width="80%"');
- foreach ($action_array as $action => $action_display) {
- echo html_tag('td', '' . $action_display . '', 'center');
- }
-
- echo '' . "\n";
- $row_num++;
+ $a = array();
+ $main_key = $query_keys[ASEARCH_WHERE];
+ $query_count = count($query_array[$main_key]);
+ for ($query_num = 0, $row_num = 0; $query_num < $query_count; $query_num++) {
+ if (!empty($query_array[$main_key][$query_num])) {
+ unset($search_array);
+ foreach ($query_keys as $query_key) {
+ $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]);
}
+
+ $where_array = $search_array[ASEARCH_WHERE];
+ $mailbox_array = $search_array[ASEARCH_MAILBOX];
+ $what_array = $search_array[ASEARCH_WHAT];
+ $unop_array = $search_array[ASEARCH_UNOP];
+ $biop_array = asearch_nz($search_array[ASEARCH_BIOP], array());
+ $exclude_array = asearch_nz($search_array[ASEARCH_EXCLUDE], array());
+ $sub_array = asearch_nz($search_array[ASEARCH_SUB], array());
+ $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
+
+ $a[$query_num] = $query_display;
}
}
- echo '' . "\n";
+
+ $oTemplate->assign('list_title', $title);
+ $oTemplate->assign('show_list', $show_flag==1);
+ $oTemplate->assign('is_recent_list', $title==_("Recent Searches"));
+ $oTemplate->assign('expand_collapse_toggle', '../src/search.php?'.$show_pref.'='.($show_flag==1 ? 0 : 1));
+ $oTemplate->assign('query_list', $a);
+
+ $oTemplate->assign('save_recent', '../src/search.php?submit=save_recent&rownum=');
+ $oTemplate->assign('do_recent', '../src/search.php?submit=search_recent&rownum=');
+ $oTemplate->assign('forget_recent', '../src/search.php?submit=forget_recent&rownum=');
+
+ $oTemplate->assign('edit_saved', '../src/search.php?submit=edit_saved&rownum=');
+ $oTemplate->assign('do_saved', '../src/search.php?submit=search_saved&rownum=');
+ $oTemplate->assign('delete_saved', '../src/search.php?submit=delete_saved&rownum=');
+
+ $oTemplate->display('search_list.tpl');
}
/** Print the saved array
+ *
+ * Function arguments are different in 1.5.0
+ * @param array $boxes (unused, see asearch_print_query_array())
+ * @since 1.5.0
+ * @private
*/
function asearch_print_saved(&$boxes)
{
@@ -666,6 +724,11 @@ function asearch_print_saved(&$boxes)
/**
* Print the recent array
+ *
+ * Function arguments are different in 1.5.0
+ * @param array $boxes (unused, see asearch_print_query_array())
+ * @since 1.5.0
+ * @private
*/
function asearch_print_recent(&$boxes)
{
@@ -681,26 +744,13 @@ function asearch_print_recent(&$boxes)
}
}
-/** Build an ' . "\n";
-}
-
-/** Build a