/**
 * Returns a search URL
 *
 * @param mixed $words the search words target
 * @param mixed $dates the dates that limit the search
 * @param mixed $fields the fields on which to search
 * @param int $page the page number for the URL
 * @param array $object_list the list of objects to search
 * @return string
 * @since 1.1.3
 */
function getSearchURL($words, $dates, $fields, $page, $object_list = NULL)
{
    if (!is_null($object_list)) {
        if (array_key_exists(0, $object_list)) {
            // handle old form albums list
            internal_deprecations::getSearchURL();
            $object_list = array('albums' => $object_list);
        }
    }
    $urls = '';
    $rewrite = false;
    if (MOD_REWRITE) {
        $rewrite = true;
        if (is_array($object_list)) {
            foreach ($object_list as $obj) {
                if ($obj) {
                    $rewrite = false;
                    break;
                }
            }
        }
    }
    if ($rewrite) {
        if (empty($dates)) {
            $url = SEO_WEBPATH . '/' . _SEARCH_ . '/';
        } else {
            $url = SEO_WEBPATH . '/' . _ARCHIVE_ . '/';
        }
    } else {
        $url = SEO_WEBPATH . "/index.php?p=search";
    }
    if (!empty($fields) && empty($dates)) {
        if (!is_array($fields)) {
            $fields = explode(',', $fields);
        }
        $temp = $fields;
        if ($rewrite && count($fields) == 1 && array_shift($temp) == 'tags') {
            $url = SEO_WEBPATH . '/' . _TAGS_ . '/';
        } else {
            $search = new SearchEngine();
            $urls = $search->getSearchFieldsText($fields, 'searchfields=');
        }
    }
    if (!empty($words)) {
        if (is_array($words)) {
            foreach ($words as $key => $word) {
                $words[$key] = search_quote($word);
            }
            $words = implode(',', $words);
        }
        $words = strtr($words, array('%' => '__25__', '&' => '__26__', '#' => '__23__', '/' => '__2F__'));
        if ($rewrite) {
            $url .= urlencode($words);
        } else {
            $url .= "&words=" . urlencode($words);
        }
    }
    if (!empty($dates)) {
        if (is_array($dates)) {
            $dates = implode(',', $dates);
        }
        if ($rewrite) {
            $url .= $dates;
        } else {
            $url .= "&date={$dates}";
        }
    }
    if ($page > 1) {
        if ($rewrite) {
            $url .= "/{$page}";
        } else {
            if ($urls) {
                $urls .= '&';
            }
            $urls .= "page={$page}";
        }
    }
    if (!empty($urls)) {
        if ($rewrite) {
            $url .= '?' . $urls;
        } else {
            $url .= '&' . $urls;
        }
    }
    if (is_array($object_list)) {
        foreach ($object_list as $key => $list) {
            if (!empty($list)) {
                $url .= '&in' . $key . '=' . html_encode(implode(',', $list));
            }
        }
    }
    return $url;
}
Example #2
0
 /**
  * recodes the search words replacing the boolean operators with text versions
  *
  * @param string $quote how to represent quoted strings
  *
  * @return string
  *
  */
 function codifySearchString($quote = '"')
 {
     $searchstring = $this->getSearchString();
     $sanitizedwords = '';
     if (is_array($searchstring)) {
         foreach ($searchstring as $singlesearchstring) {
             switch ($singlesearchstring) {
                 case '&':
                     $sanitizedwords .= " AND ";
                     break;
                 case '|':
                     $sanitizedwords .= " OR ";
                     break;
                 case '!':
                     $sanitizedwords .= " NOT ";
                     break;
                 case '(':
                 case ')':
                     $sanitizedwords .= "{$singlesearchstring}";
                     break;
                 default:
                     $sanitizedword = sanitize($singlesearchstring, 3);
                     $setQuote = $sanitizedword != $singlesearchstring;
                     if (!$setQuote) {
                         $setQuote = is_numeric($singlesearchstring) || preg_match("/[ &|!'\"`,()]/", $singlesearchstring);
                     }
                     if ($setQuote) {
                         $sanitizedwords .= search_quote($singlesearchstring);
                     } else {
                         $sanitizedwords .= ' ' . sanitize($singlesearchstring, 3) . ' ';
                     }
                     break;
             }
         }
     }
     $sanitizedwords = trim(str_replace(array('   ', '  '), ' ', $sanitizedwords));
     $sanitizedwords = trim(str_replace('( ', '(', $sanitizedwords));
     $sanitizedwords = trim(str_replace(' )', ')', $sanitizedwords));
     return $sanitizedwords;
 }
Example #3
0
 /**
  * recodes the search words replacing the boolean operators with text versions
  *
  * @param string $quote how to represent quoted strings
  *
  * @return string
  *
  */
 function codifySearchString()
 {
     $searchstring = $this->getSearchString();
     $sanitizedwords = '';
     if (is_array($searchstring)) {
         foreach ($searchstring as $singlesearchstring) {
             switch ($singlesearchstring) {
                 case '&':
                     $sanitizedwords .= " AND ";
                     break;
                 case '|':
                     $sanitizedwords .= " OR ";
                     break;
                 case '!':
                     $sanitizedwords .= " NOT ";
                     break;
                 case '(':
                 case ')':
                     $sanitizedwords .= $singlesearchstring;
                     break;
                 default:
                     $sanitizedwords .= search_quote(sanitize($singlesearchstring, 3));
                     break;
             }
         }
     }
     $sanitizedwords = trim(str_replace(array('   ', '  '), ' ', $sanitizedwords));
     $sanitizedwords = trim(str_replace('( ', '(', $sanitizedwords));
     $sanitizedwords = trim(str_replace(' )', ')', $sanitizedwords));
     return $sanitizedwords;
 }
/**
 * Returns a search URL
 *
 * @param mixed $words the search words target
 * @param mixed $dates the dates that limit the search
 * @param mixed $fields the fields on which to search
 * NOTE: $words and $dates are mutually exclusive and $fields applies only to $words searches
 * @param int $page the page number for the URL
 * @param array $object_list the list of objects to search
 * @return string
 * @since 1.1.3
 */
function getSearchURL($words, $dates, $fields, $page, $object_list = NULL)
{
    $urls = array();
    $rewrite = false;
    if (MOD_REWRITE) {
        $rewrite = true;
        if (is_array($object_list)) {
            foreach ($object_list as $obj) {
                if ($obj) {
                    $rewrite = false;
                    break;
                }
            }
        }
    }
    if ($rewrite) {
        $url = SEO_WEBPATH . '/' . _SEARCH_ . '/';
    } else {
        $url = SEO_WEBPATH . "/index.php";
        $urls[] = 'p=search';
    }
    if ($words) {
        if (is_array($words)) {
            foreach ($words as $key => $word) {
                $words[$key] = search_quote($word);
            }
            $words = implode(',', $words);
        }
        $words = SearchEngine::encode($words);
        if ($rewrite) {
            $url .= $words . '/';
        } else {
            $urls[] = 'words=' . $words;
        }
        if (!empty($fields)) {
            if (!is_array($fields)) {
                $fields = explode(',', $fields);
            }
            $temp = $fields;
            if ($rewrite && count($fields) == 1 && array_shift($temp) == 'tags') {
                $url = SEO_WEBPATH . '/' . _TAGS_ . '/' . $words . '/';
            } else {
                $search = new SearchEngine();
                $urls[] = $search->getSearchFieldsText($fields, 'searchfields=');
            }
        }
    } else {
        //	dates
        if (is_array($dates)) {
            $dates = implode(',', $dates);
        }
        if ($rewrite) {
            $url = SEO_WEBPATH . '/' . _ARCHIVE_ . '/' . $dates . '/';
        } else {
            $urls[] = "date={$dates}";
        }
    }
    if ($page > 1) {
        if ($rewrite) {
            $url .= $page;
        } else {
            $urls[] = "page={$page}";
        }
    }
    if (is_array($object_list)) {
        foreach ($object_list as $key => $list) {
            if (!empty($list)) {
                if (is_array($list)) {
                    $list = implode(',', $list);
                }
                $urls[] = 'in' . $key . '=' . urlencode($list);
            }
        }
    }
    if (!empty($urls)) {
        $url .= '?' . implode('&', $urls);
    }
    return $url;
}
/**
 * Returns a search URL
 *
 * @param mixed $words the search words target
 * @param mixed $dates the dates that limit the search
 * @param mixed $fields the fields on which to search
 * @param int $page the page number for the URL
 * @param array $object_list the list of objects to search
 * @return string
 * @since 1.1.3
 */
function getSearchURL($words, $dates, $fields, $page, $object_list = NULL)
{
    if (!is_null($object_list)) {
        if (array_key_exists(0, $object_list)) {
            // handle old form albums list
            require_once SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/deprecated-functions.php';
            deprecated_function_notify(gettext('getSearchURL $album_list parameter is deprecated. Pass array("albums"=>array(album, album, ...)) instead.'));
            $object_list = array('albums' => $object_list);
        }
    }
    if ($mr = MOD_REWRITE) {
        $url = WEBPATH . "/page/search/";
    } else {
        $url = WEBPATH . "/index.php?p=search";
    }
    if (!empty($fields) && empty($dates)) {
        if (!is_array($fields)) {
            $fields = explode(',', $fields);
        }
        $temp = $fields;
        if ($mr && count($fields) == 1 && array_shift($temp) == 'tags') {
            $url .= "tags/";
            $urls = '';
        } else {
            $search = new SearchEngine();
            $urls = $search->getSearchFieldsText($fields, 'searchfields=');
        }
    }
    if (!empty($words)) {
        if (is_array($words)) {
            foreach ($words as $key => $word) {
                $words[$key] = search_quote($word);
            }
            $words = implode(',', $words);
        }
        if (MOD_REWRITE) {
            $url .= urlencode($words);
        } else {
            $url .= "&words=" . urlencode($words);
        }
    }
    if (!empty($dates)) {
        if (is_array($dates)) {
            $dates = implode(',', $dates);
        }
        if (MOD_REWRITE) {
            $url .= "archive/{$dates}";
        } else {
            $url .= "&date={$dates}";
        }
    }
    if ($page > 1) {
        if ($mr) {
            $url .= "/{$page}";
        } else {
            $urls .= $urls ? '&' : '' . "page={$page}";
        }
    }
    if (!empty($urls)) {
        if (MOD_REWRITE) {
            $url .= '?' . $urls;
        } else {
            $url .= '&' . $urls;
        }
    }
    if (is_array($object_list)) {
        foreach ($object_list as $key => $list) {
            if (!empty($list)) {
                $mr = false;
                $url .= '&in' . $key . '=' . html_encode(implode(',', $list));
            }
        }
    }
    return $url;
}