New module 'Custom Search'
This commit is contained in:
parent
21fa3db391
commit
80408e0950
28 changed files with 2970 additions and 0 deletions
339
sites/all/modules/custom_search/LICENSE.txt
Normal file
339
sites/all/modules/custom_search/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
44
sites/all/modules/custom_search/README.txt
Normal file
44
sites/all/modules/custom_search/README.txt
Normal file
|
@ -0,0 +1,44 @@
|
|||
|
||||
Custom search 6.x-1.x
|
||||
--------------------------
|
||||
|
||||
Install
|
||||
-------
|
||||
* Enable the module
|
||||
* Go to Administer > Settings > Custom search to change settings
|
||||
* Don't forget to set permissions, otherwise nobody will see the changes
|
||||
|
||||
Description
|
||||
-----------
|
||||
This module alters the default search box in many ways. If you need to have options available like in advanced search, but directly in the search box, this module is for you.
|
||||
|
||||
The module adds options to select:
|
||||
|
||||
- which content type(s) to search,
|
||||
- which specific module search to use (node, help, user or any module that implements search),
|
||||
- which taxonomy term to search in the results (by vocabulary).
|
||||
- For all these choices, there are options to switch between a select box, checkboxes or radio buttons, and also customize the selector label and the default - Any - text.
|
||||
|
||||
There are also options to:
|
||||
|
||||
- change the default search box label,
|
||||
- adds a default text in the search box,
|
||||
- change the default submit button text,
|
||||
- use an image instead of the submit button,
|
||||
- via a "tabledrag", the ordering of all the added options can be changed.
|
||||
|
||||
Finally, there's some javascript to:
|
||||
|
||||
- check if the search box is not empty on submit,
|
||||
- clear the default text on focus, and put it back on blur (if search box is empty),
|
||||
- handle checkboxes (deselect some checkbox if -Any-, or a special module search, is checked),
|
||||
- reselect options in the advanced search options (in results page).
|
||||
|
||||
|
||||
The module integrates well with Internationalization (i18nstrings).
|
||||
|
||||
This module is inspired by some modules that implements some of these options (search_config, search_type, custom_seach_box).
|
||||
|
||||
Author
|
||||
------
|
||||
jdanthinne
|
199
sites/all/modules/custom_search/custom_search.admin.inc
Normal file
199
sites/all/modules/custom_search/custom_search.admin.inc
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Admin settings for custom search
|
||||
*/
|
||||
|
||||
function custom_search_admin() {
|
||||
$directory_path = file_directory_path() . '/custom_search';
|
||||
file_check_directory($directory_path, FILE_CREATE_DIRECTORY);
|
||||
// Check for a new uploaded image.
|
||||
if ($file = file_save_upload('custom_search_image', array('file_validate_is_image' => array()))) {
|
||||
if (file_copy($file, $directory_path)) {
|
||||
$_POST['custom_search_image_path'] = $file->filepath;
|
||||
}
|
||||
}
|
||||
|
||||
// Basic settings.
|
||||
$form = _custom_search_default_admin_form();
|
||||
// Custom search paths.
|
||||
$form = array_merge($form, _custom_search_custom_paths_admin_form());
|
||||
// Ordering.
|
||||
$form = array_merge($form, _custom_search_ordering_admin_form());
|
||||
|
||||
$form['#attributes'] = array('enctype' => 'multipart/form-data');
|
||||
$form['#submit'][] = 'custom_search_admin_submit';
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback to save the ordering
|
||||
*/
|
||||
function custom_search_admin_submit($form, &$form_state) {
|
||||
foreach ($form_state['values']['custom_search_order'] as $key => $data) {
|
||||
variable_set('custom_search_' . $key . '_weight', $data['sort']);
|
||||
variable_set('custom_search_' . $key . '_region', $data['region']);
|
||||
}
|
||||
}
|
||||
|
||||
function custom_search_content_admin() {
|
||||
return system_settings_form(_custom_search_content_admin_form());
|
||||
}
|
||||
|
||||
function custom_search_results_admin() {
|
||||
$form['custom_search_target'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Results page opens in'),
|
||||
'#options' => array(
|
||||
'_self' => t('the same window'),
|
||||
'_blank' => t('a new window'),
|
||||
),
|
||||
'#default_value' => variable_get('custom_search_target', '_self'),
|
||||
);
|
||||
|
||||
$form['search_form'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Search forms'),
|
||||
);
|
||||
$form['search_form']['custom_search_results_search'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display basic search'),
|
||||
'#default_value' => variable_get('custom_search_results_search', TRUE),
|
||||
);
|
||||
$form['search_form']['advanced'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Advanced search'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['search_form']['advanced']['custom_search_results_advanced_search'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display advanced search'),
|
||||
'#default_value' => variable_get('custom_search_results_advanced_search', TRUE),
|
||||
);
|
||||
$form['search_form']['advanced']['custom_search_results_advanced_search_collapsible'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Collapsible'),
|
||||
'#default_value' => variable_get('custom_search_results_advanced_search_collapsible', TRUE),
|
||||
);
|
||||
$form['search_form']['advanced']['custom_search_results_advanced_search_collapsed'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Collapsed'),
|
||||
'#default_value' => variable_get('custom_search_results_advanced_search_collapsed', TRUE),
|
||||
);
|
||||
$form['search_form']['advanced']['criteria'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Criteria'),
|
||||
'#description' => t('Select the criteria to display on the advanced search form.'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['search_form']['advanced']['criteria']['custom_search_advanced_or_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Or'),
|
||||
'#default_value' => variable_get('custom_search_advanced_or_display', TRUE),
|
||||
);
|
||||
$form['search_form']['advanced']['criteria']['custom_search_advanced_phrase_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Phrase'),
|
||||
'#default_value' => variable_get('custom_search_advanced_phrase_display', TRUE),
|
||||
);
|
||||
$form['search_form']['advanced']['criteria']['custom_search_advanced_negative_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Negative'),
|
||||
'#default_value' => variable_get('custom_search_advanced_negative_display', TRUE),
|
||||
);
|
||||
$form['search_form']['advanced']['types'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Content types'),
|
||||
'#description' => t('Select the content types to display on the advanced search form.'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$options = node_get_types('names');
|
||||
foreach ($options as $type => $name) {
|
||||
$form['search_form']['advanced']['types']['custom_search_advanced_type_' . $type . '_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $name,
|
||||
'#default_value' => variable_get('custom_search_advanced_type_' . $type . '_display', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
if (module_exists('taxonomy')) {
|
||||
$form['search_form']['advanced']['taxonomy'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Taxonomy'),
|
||||
'#description' => t('Select the vocabularies to display on the advanced search form.'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
$form['search_form']['advanced']['taxonomy']['custom_search_advanced_voc' . $voc->vid . '_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $voc->name,
|
||||
'#default_value' => variable_get('custom_search_advanced_voc' . $voc->vid . '_display', TRUE),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$form['results'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Results'),
|
||||
'#description' => t('Select data to display below each result.'),
|
||||
);
|
||||
$form['results']['custom_search_results_info_type'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Content type'),
|
||||
'#default_value' => variable_get('custom_search_results_info_type', TRUE),
|
||||
);
|
||||
$form['results']['custom_search_results_info_user'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('User'),
|
||||
'#default_value' => variable_get('custom_search_results_info_user', TRUE),
|
||||
);
|
||||
$form['results']['custom_search_results_info_date'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Date'),
|
||||
'#default_value' => variable_get('custom_search_results_info_date', TRUE),
|
||||
);
|
||||
if (module_exists('comment')) {
|
||||
$form['results']['custom_search_results_info_comment'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Comments'),
|
||||
'#default_value' => variable_get('custom_search_results_info_comment', TRUE),
|
||||
);
|
||||
}
|
||||
if (module_exists('upload')) {
|
||||
$form['results']['custom_search_results_info_upload'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Uploads'),
|
||||
'#default_value' => variable_get('custom_search_results_info_upload', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
$form['filter'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Filter'),
|
||||
'#description' => t('Add links to filter the results by content type.'),
|
||||
);
|
||||
$form['filter']['custom_search_filter'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Position'),
|
||||
'#options' => array(
|
||||
'disabled' => t('Disabled'),
|
||||
'above' => t('Above results'),
|
||||
'below' => t('Below results'),
|
||||
),
|
||||
'#default_value' => variable_get('custom_search_filter', 'disabled'),
|
||||
);
|
||||
$form['filter']['custom_search_filter_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label text'),
|
||||
'#default_value' => variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT),
|
||||
'#description' => t('Enter the label text for the list. The default value is "!default".', array('!default' => CUSTOM_SEARCH_FILTER_LABEL_DEFAULT)),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
20
sites/all/modules/custom_search/custom_search.css
Normal file
20
sites/all/modules/custom_search/custom_search.css
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
#elements tr.region-message {
|
||||
font-weight: normal;
|
||||
color: #999;
|
||||
}
|
||||
#elements tr.region-populated {
|
||||
display: none;
|
||||
}
|
||||
|
||||
fieldset.custom_search-popup {
|
||||
display: none;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
input.custom-search-default-value { color:#999;}
|
||||
.element-invisible {
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
}
|
11
sites/all/modules/custom_search/custom_search.info
Normal file
11
sites/all/modules/custom_search/custom_search.info
Normal file
|
@ -0,0 +1,11 @@
|
|||
name = Custom Search
|
||||
description = Customize the default search, change labels, default texts, ordering, and display content types and taxonomy selectors.
|
||||
core = 6.x
|
||||
package = Custom Search
|
||||
dependencies[] = search
|
||||
; Information added by Drupal.org packaging script on 2014-04-23
|
||||
version = "6.x-1.13"
|
||||
core = "6.x"
|
||||
project = "custom_search"
|
||||
datestamp = "1398258531"
|
||||
|
129
sites/all/modules/custom_search/custom_search.install
Normal file
129
sites/all/modules/custom_search/custom_search.install
Normal file
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update, and uninstall functions for the custom search module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function custom_search_install() {
|
||||
db_query("UPDATE {system} SET weight = 100 WHERE name = 'custom_search'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function custom_search_uninstall() {
|
||||
variable_del('custom_search_label_visibility');
|
||||
variable_del('custom_search_label');
|
||||
variable_del('custom_search_text');
|
||||
variable_del('custom_search_size');
|
||||
variable_del('custom_search_max_length');
|
||||
variable_del('custom_search_submit_text');
|
||||
variable_del('custom_search_image_path');
|
||||
variable_del('custom_search_criteria_or_display');
|
||||
variable_del('custom_search_criteria_or_label');
|
||||
variable_del('custom_search_criteria_phrase_display');
|
||||
variable_del('custom_search_criteria_phrase_label');
|
||||
variable_del('custom_search_criteria_negative_display');
|
||||
variable_del('custom_search_criteria_negative_label');
|
||||
variable_del('custom_search_paths');
|
||||
variable_del('custom_search_paths_selector');
|
||||
variable_del('custom_search_paths_selector_label');
|
||||
variable_del('custom_search_paths_selector_label_visibility');
|
||||
variable_del('custom_search_search_box_weight');
|
||||
variable_del('custom_search_content_types_weight');
|
||||
variable_del('custom_search_criteria_or_weight');
|
||||
variable_del('custom_search_criteria_phrase_weight');
|
||||
variable_del('custom_search_criteria_negative_weight');
|
||||
variable_del('custom_search_custom_paths_weight');
|
||||
variable_del('custom_search_submit_button_weight');
|
||||
variable_del('custom_search_search_box_region');
|
||||
variable_del('custom_search_content_types_region');
|
||||
variable_del('custom_search_criteria_or_region');
|
||||
variable_del('custom_search_criteria_phrase_region');
|
||||
variable_del('custom_search_criteria_negative_region');
|
||||
variable_del('custom_search_custom_paths_region');
|
||||
variable_del('custom_search_submit_button_region');
|
||||
variable_del('custom_search_target');
|
||||
variable_del('custom_search_node_types');
|
||||
variable_del('custom_search_node_types_excluded');
|
||||
variable_del('custom_search_other');
|
||||
variable_del('custom_search_type_selector');
|
||||
variable_del('custom_search_type_selector_label');
|
||||
variable_del('custom_search_type_selector_label_visibility');
|
||||
variable_del('custom_search_type_selector_all');
|
||||
variable_del('custom_search_any_restricts');
|
||||
variable_del('custom_search_any_force');
|
||||
variable_del('custom_search_results_search');
|
||||
variable_del('custom_search_results_advanced_search');
|
||||
variable_del('custom_search_results_advanced_search_collapsible');
|
||||
variable_del('custom_search_results_advanced_search_collapsed');
|
||||
variable_del('custom_search_advanced_or_display');
|
||||
variable_del('custom_search_advanced_phrase_display');
|
||||
variable_del('custom_search_advanced_negative_display');
|
||||
$options = node_get_types('names');
|
||||
foreach ($options as $type => $name) variable_del('custom_search_advanced_type_' . $type . '_display');
|
||||
variable_del('custom_search_results_info_type');
|
||||
variable_del('custom_search_results_info_user');
|
||||
variable_del('custom_search_results_info_date');
|
||||
if (module_exists('comment')) variable_del('custom_search_results_info_comment');
|
||||
if (module_exists('upload')) variable_del('custom_search_results_info_upload');
|
||||
variable_del('custom_search_filter');
|
||||
variable_del('custom_search_filter_label');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_enable().
|
||||
*/
|
||||
function custom_search_enable() {
|
||||
drupal_set_message(t('Custom Search enabled. Don\'t forget to <a href="@link">set permissions</a>.', array('@link' => url('admin/user/permissions', array('fragment' => 'module-custom_search')))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the module weight.
|
||||
*/
|
||||
function custom_search_update_6100() {
|
||||
$ret = array();
|
||||
$ret[] = update_sql("UPDATE {system} SET weight = 100 WHERE name = 'custom_search'");
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function custom_search_update_6101() {
|
||||
$ret = array();
|
||||
drupal_set_message(t('Custom Search has been divided in multiple modules. Please re-enable the sub-modules you need.'));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function custom_search_update_6102() {
|
||||
$ret = array();
|
||||
if (variable_get('custom_search_path', '') != '') {
|
||||
variable_set('custom_search_paths', variable_get('custom_search_path', '') . '|Custom path');
|
||||
}
|
||||
variable_del('custom_search_path');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function custom_search_update_6103() {
|
||||
$ret = array();
|
||||
if (variable_get('custom_search_results_advanced_override', FALSE)) {
|
||||
variable_set('custom_search_advanced_or_display', variable_get('custom_search_criteria_or_display', FALSE));
|
||||
variable_set('custom_search_advanced_phrase_display', variable_get('custom_search_criteria_phrase_display', FALSE));
|
||||
variable_set('custom_search_advanced_negative_display', variable_get('custom_search_criteria_negative_display', FALSE));
|
||||
$types = array_keys(array_filter(variable_get('custom_search_node_types', array())));
|
||||
if (count($types)) {
|
||||
$names = array_keys(node_get_types('names'));
|
||||
foreach ($names as $name) {
|
||||
if (!in_array($name, $types)) variable_set('custom_search_advanced_type_' . $name . '_display', FALSE);
|
||||
}
|
||||
}
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
if (variable_get('custom_search_voc' . $voc->vid . '_selector', 'disabled') == 'disabled') variable_set('custom_search_advanced_voc' . $voc->vid . '_display', FALSE);
|
||||
}
|
||||
}
|
||||
variable_del('custom_search_results_advanced_override');
|
||||
return $ret;
|
||||
}
|
490
sites/all/modules/custom_search/custom_search.module
Normal file
490
sites/all/modules/custom_search/custom_search.module
Normal file
|
@ -0,0 +1,490 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Bring customizations to the default search box
|
||||
*
|
||||
* Adds node types and taxonomy options to the search form
|
||||
*/
|
||||
|
||||
define('CUSTOM_SEARCH_LABEL_DEFAULT', t('Search this site'));
|
||||
define('CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT', t('Search'));
|
||||
define('CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT', t('Search for'));
|
||||
define('CUSTOM_SEARCH_MAX_LENGTH_DEFAULT', 128);
|
||||
define('CUSTOM_SEARCH_SIZE_DEFAULT', 15);
|
||||
define('CUSTOM_SEARCH_ALL_TEXT_DEFAULT', t('-Any-'));
|
||||
define('CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT', t('Containing any of the words'));
|
||||
define('CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT', t('Containing the phrase'));
|
||||
define('CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT', t('Containing none of the words'));
|
||||
define('CUSTOM_SEARCH_FILTER_LABEL_DEFAULT', t('Filter the results'));
|
||||
define('CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT', t('Customize your search'));
|
||||
define('CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT', '+');
|
||||
|
||||
/**
|
||||
* Includes
|
||||
*/
|
||||
module_load_include('inc', 'custom_search', 'includes/forms');
|
||||
module_load_include('inc', 'custom_search', 'includes/apachesolr_search');
|
||||
module_load_include('inc', 'custom_search', 'includes/google_appliance');
|
||||
module_load_include('inc', 'custom_search', 'includes/luceneapi_node');
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu().
|
||||
*/
|
||||
function custom_search_menu() {
|
||||
$items['admin/settings/custom_search'] = array(
|
||||
'title' => 'Custom Search',
|
||||
'description' => 'Customize the default search, change labels, default texts, ordering, and display content types and taxonomy selectors.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_search_admin'),
|
||||
'access arguments' => array('administer custom search'),
|
||||
'file' => 'custom_search.admin.inc',
|
||||
);
|
||||
$items['admin/settings/custom_search/settings'] = array(
|
||||
'title' => 'Settings',
|
||||
'description' => 'Change the labels, the default texts and the ordering of elements.',
|
||||
'access arguments' => array('administer custom search'),
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => 0,
|
||||
);
|
||||
$items['admin/settings/custom_search/content'] = array(
|
||||
'title' => 'Content',
|
||||
'description' => 'Select the content types to present as search options in the search block.',
|
||||
'page arguments' => array('custom_search_content_admin'),
|
||||
'access arguments' => array('administer custom search'),
|
||||
'file' => 'custom_search.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 1,
|
||||
);
|
||||
$items['admin/settings/custom_search/results'] = array(
|
||||
'title' => 'Results page',
|
||||
'description' => 'Customize the search results page.',
|
||||
'page arguments' => array('custom_search_results_admin'),
|
||||
'access arguments' => array('administer custom search'),
|
||||
'file' => 'custom_search.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 4,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu_alter().
|
||||
* (needed for compatibility with Search Ranking)
|
||||
*/
|
||||
function custom_search_menu_alter(&$callbacks) {
|
||||
// Panels integration
|
||||
if ($callbacks['search/node/%menu_tail']['page callback'] == 'page_manager_search_page') return;
|
||||
|
||||
$callbacks['search/node/%menu_tail']['page callback'] = 'search_view';
|
||||
$callbacks['search/node/%menu_tail']['file'] = 'search.pages.inc';
|
||||
$callbacks['search/node/%menu_tail']['file path'] = drupal_get_path('module', 'search');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_perm().
|
||||
*/
|
||||
function custom_search_perm() {
|
||||
return array('administer custom search', 'use custom search');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter().
|
||||
*/
|
||||
function custom_search_form_alter(&$form, $form_state, $form_id) {
|
||||
|
||||
// Filter the form_id value to identify all the custom blocks
|
||||
$form_id_processed = $form_id;
|
||||
$delta = '';
|
||||
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
|
||||
if ($form_id == 'custom_search_blocks_form_' . $a) {
|
||||
$form_id_processed = 'custom_search_blocks_form';
|
||||
$delta = 'blocks_' . $a . '_';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($form_id_processed) {
|
||||
|
||||
case 'search_form':
|
||||
|
||||
if (isset($form['advanced'])) {
|
||||
|
||||
// Criteria
|
||||
if (!variable_get('custom_search_advanced_or_display', TRUE)) $form['advanced']['keywords']['or']['#type'] = 'hidden';
|
||||
if (!variable_get('custom_search_advanced_phrase_display', TRUE)) $form['advanced']['keywords']['phrase']['#type'] = 'hidden';
|
||||
if (!variable_get('custom_search_advanced_negative_display', TRUE)) $form['advanced']['keywords']['negative']['#type'] = 'hidden';
|
||||
|
||||
// Taxonomy
|
||||
if (module_exists('taxonomy')) {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
if (!variable_get('custom_search_advanced_voc' . $voc->vid . '_display', TRUE)) unset($form['advanced']['category']['#options'][$voc->name]);
|
||||
}
|
||||
if (!count($form['advanced']['category']['#options'])) unset($form['advanced']['category']['#type']);
|
||||
}
|
||||
|
||||
// Content Types
|
||||
$names = array_keys(node_get_types('names'));
|
||||
foreach ($names as $name) {
|
||||
if (!variable_get('custom_search_advanced_type_' . $name . '_display', TRUE)) unset($form['advanced']['type']['#options'][$name]);
|
||||
}
|
||||
if (!count($form['advanced']['type']['#options'])) unset($form['advanced']['type']['#type']);
|
||||
|
||||
if (!variable_get('custom_search_results_search', TRUE)) {
|
||||
// If basic search is hidded, original search terms are imported into advanced search.
|
||||
$original_keys = $form['basic']['inline']['keys']['#default_value'];
|
||||
$temp_keys = explode(' ', $original_keys);
|
||||
foreach ($temp_keys as $value) {
|
||||
if (drupal_substr($value, 0, 5) != 'type:' && drupal_substr($value, 0, 9) != 'category:') $keys[] = $value;
|
||||
}
|
||||
$form['advanced']['keywords']['or']['#default_value'] = implode(' ', $keys);
|
||||
if (!isset($GLOBALS['custom_search_nb_results']) || (isset($GLOBALS['custom_search_nb_results']) && !$GLOBALS['custom_search_nb_results'])) $form['advanced']['#collapsed'] = FALSE;
|
||||
$form['basic']['#prefix'] = '<div class="element-invisible">';
|
||||
$form['basic']['#suffix'] = '</div>';
|
||||
}
|
||||
|
||||
$form['advanced']['#collapsible'] = variable_get('custom_search_results_advanced_search_collapsible', TRUE);
|
||||
$form['advanced']['#collapsed'] = variable_get('custom_search_results_advanced_search_collapsed', TRUE);
|
||||
|
||||
if (!variable_get('custom_search_results_advanced_search', TRUE)) $form['advanced']['#type'] = 'hidden';
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'search_theme_form':
|
||||
case 'search_block_form':
|
||||
case 'custom_search_blocks_form':
|
||||
if (user_access('use custom search')) {
|
||||
|
||||
// Title.
|
||||
$form[$form_id]['#title'] = variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT);
|
||||
if (!variable_get('custom_search_' . $delta . 'label_visibility', TRUE)) $form[$form_id]['#post_render'] = array('_custom_search_hide_label');
|
||||
|
||||
// Search box.
|
||||
$form[$form_id]['#default_value'] = variable_get('custom_search_' . $delta . 'text', '');
|
||||
$form[$form_id]['#weight'] = variable_get('custom_search_' . $delta . 'search_box_weight', 0);
|
||||
if (!isset($form[$form_id]['#attributes']['class'])) $form[$form_id]['#attributes']['class'] = '';
|
||||
$form[$form_id]['#attributes']['class'] .= ' custom-search-default-value custom-search-box';
|
||||
$form[$form_id]['#size'] = variable_get('custom_search_' . $delta . 'size', CUSTOM_SEARCH_SIZE_DEFAULT);
|
||||
$form[$form_id]['#maxlength'] = variable_get('custom_search_' . $delta . 'max_length', CUSTOM_SEARCH_MAX_LENGTH_DEFAULT);
|
||||
|
||||
// Default text.
|
||||
$form['default_text'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'text', ''),
|
||||
'#attributes' => array('class' => 'default-text'),
|
||||
);
|
||||
|
||||
// CSS
|
||||
drupal_add_css(drupal_get_path('module', 'custom_search') . '/custom_search.css', 'module');
|
||||
|
||||
// Criterion
|
||||
$criteria = array('or' => 6, 'phrase' => 7, 'negative' => 8);
|
||||
foreach ($criteria as $c => $w) {
|
||||
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_display', FALSE)) {
|
||||
$form['custom_search_criteria_' . $c] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => variable_get('custom_search_' . $delta . 'criteria_' . $c . '_label', constant('CUSTOM_SEARCH_CRITERIA_' . strtoupper($c) . '_LABEL_DEFAULT')),
|
||||
'#size' => 15,
|
||||
'#maxlength' => 255,
|
||||
'#weight' => variable_get('custom_search_' . $delta . 'criteria_' . $c . '_weight', $w),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Content type & other searches.
|
||||
// Content types.
|
||||
$toptions = array();
|
||||
$types = array_keys(array_filter(variable_get('custom_search_' . $delta . 'node_types', array())));
|
||||
if (count($types)) {
|
||||
$names = node_get_types('names');
|
||||
if (count($types) > 1 || variable_get('custom_search_' . $delta . 'any_force', FALSE)) $toptions['c-all'] = variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT);
|
||||
foreach ($types as $type) {
|
||||
$toptions['c-' . $type] = $names[$type];
|
||||
}
|
||||
}
|
||||
$options = array();
|
||||
// Other searches.
|
||||
$others = array_keys(array_filter(variable_get('custom_search_' . $delta . 'other', array())));
|
||||
// If content types and other searches are combined, make an optgroup.
|
||||
if (count($others) && count($toptions) && variable_get('custom_search_' . $delta . 'type_selector', 'select') == 'select') {
|
||||
$content = module_invoke('node', 'search', 'name');
|
||||
$options[$content] = $toptions;
|
||||
}
|
||||
else {
|
||||
$options = $toptions;
|
||||
}
|
||||
foreach (module_implements('search') as $module) {
|
||||
if ($module != 'node' && $name = module_invoke($module, 'search', 'name')) {
|
||||
if (in_array($module, $others)) $options['o-' . $module] = $name;
|
||||
}
|
||||
}
|
||||
if (count($options)) {
|
||||
$selector_type = variable_get('custom_search_' . $delta . 'type_selector', 'select');
|
||||
if ($selector_type == 'selectmultiple') {
|
||||
$selector_type = 'select';
|
||||
$multiple = TRUE;
|
||||
}
|
||||
else $multiple = FALSE;
|
||||
$form['custom_search_types'] = array(
|
||||
'#type' => $selector_type,
|
||||
'#multiple' => $multiple,
|
||||
'#title' => variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT),
|
||||
'#options' => $options,
|
||||
'#default_value' => ((variable_get('custom_search_' . $delta . 'type_selector', 'select') == 'checkboxes') ? array('c-all') : 'c-all'),
|
||||
'#attributes' => ($selector_type != 'radios' && $selector_type != 'checkboxes') ? array('class' => 'custom-search-selector custom-search-types') : array(),
|
||||
'#prefix' => ($selector_type == 'radios' || $selector_type == 'checkboxes') ? '<div class="custom-search-selector custom-search-types">' : '',
|
||||
'#suffix' => ($selector_type == 'radios' || $selector_type == 'checkboxes') ? '</div>' : '',
|
||||
'#weight' => variable_get('custom_search_' . $delta . 'content_types_weight', 1),
|
||||
'#validated' => TRUE,
|
||||
);
|
||||
|
||||
// If there's only one type, hide the selector
|
||||
if (count($others) + count($types) == 1 && !variable_get('custom_search_' . $delta . 'any_force', FALSE)) {
|
||||
$form['custom_search_types']['#type'] = 'hidden';
|
||||
$form['custom_search_types']['#default_value'] = key(array_slice($options, count($options)-1));
|
||||
}
|
||||
|
||||
if (!variable_get('custom_search_' . $delta . 'type_selector_label_visibility', TRUE)) $form['custom_search_types']['#post_render'] = array('_custom_search_hide_label');
|
||||
}
|
||||
|
||||
// Custom paths
|
||||
if (variable_get('custom_search_' . $delta . 'paths', '') != '') {
|
||||
$options = array();
|
||||
$lines = explode("\n", variable_get('custom_search_' . $delta . 'paths', ''));
|
||||
foreach ($lines as $line) {
|
||||
$temp = explode('|', $line);
|
||||
$options[$temp[0]] = (count($temp) >= 2) ? t($temp[1]) : '';
|
||||
}
|
||||
if (count($options) == 1) {
|
||||
$form['custom_search_paths'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => key($options),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['custom_search_paths'] = array(
|
||||
'#type' => variable_get('custom_search_' . $delta . 'paths_selector', 'select'),
|
||||
'#title' => variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT),
|
||||
'#options' => $options,
|
||||
'#default_value' => key($options),
|
||||
'#weight' => variable_get('custom_search_' . $delta . 'custom_paths_weight', 9),
|
||||
);
|
||||
if (!variable_get('custom_search_' . $delta . 'paths_selector_label_visibility', TRUE)) $form['custom_search_paths']['#post_render'] = array('_custom_search_hide_label');
|
||||
}
|
||||
}
|
||||
|
||||
// Submit button.
|
||||
$form['submit']['#value'] = variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT);
|
||||
|
||||
if (variable_get('custom_search_' . $delta . 'image_path', '') != '') {
|
||||
$form['submit']['#type'] = 'image_button';
|
||||
$form['submit']['#src'] = variable_get('custom_search_' . $delta . 'image_path', '');
|
||||
$form['submit']['#name'] = 'op';
|
||||
$form['submit']['#attributes'] = array('alt' => variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT), 'class' => 'custom-search-button');
|
||||
}
|
||||
elseif ($form['submit']['#value'] == '') $form['submit']['#attributes'] = array('style' => 'display:none;');
|
||||
|
||||
$form['submit']['#weight'] = variable_get('custom_search_' . $delta . 'submit_button_weight', 3);
|
||||
|
||||
// Popup
|
||||
$form['popup'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#weight' => 1 + variable_get('custom_search_' . $delta . 'search_box_weight', 0),
|
||||
'#attributes' => array('class' => 'custom_search-popup'),
|
||||
);
|
||||
if (!empty($form['custom_search_types']) && variable_get('custom_search_' . $delta . 'content_types_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_types'] = $form['custom_search_types'];
|
||||
unset($form['custom_search_types']);
|
||||
}
|
||||
if (!empty($form['custom_search_paths']) && variable_get('custom_search_' . $delta . 'custom_paths_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_paths'] = $form['custom_search_paths'];
|
||||
unset($form['custom_search_paths']);
|
||||
}
|
||||
foreach ($criteria as $c => $w) {
|
||||
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_display', FALSE) && variable_get('custom_search_' . $delta . 'criteria_' . $c . '_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_criteria_' . $c] = $form['custom_search_criteria_' . $c];
|
||||
unset($form['custom_search_criteria_' . $c]);
|
||||
}
|
||||
}
|
||||
|
||||
// Form attributes
|
||||
$form['#attributes']['class'] = 'search-form';
|
||||
$form['#submit'][] = 'custom_search_submit';
|
||||
$form['form_token']['#default_value'] = drupal_get_token($form_id);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the search to respect the search modes selected.
|
||||
*/
|
||||
function custom_search_submit($form, &$form_state) {
|
||||
$delta = (isset($form_state['values']['delta'])) ? 'blocks_' . $form_state['values']['delta'] . '_' : '' ;
|
||||
variable_set('custom_search_delta', $delta); // save for later use (exclusion & refresh)
|
||||
$type = 'node';
|
||||
$keys = $form_state['values'][$form_state['values']['form_id']];
|
||||
|
||||
$types = $form_state['values']['custom_search_types'];
|
||||
if (!is_array($types)) $types = array($types);
|
||||
$types = array_map('_custom_search_filter_keys', array_filter($types));
|
||||
|
||||
if (module_exists('taxonomy')) {
|
||||
$terms = array();
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
$vterms = $form_state['values']['custom_search_vocabulary_' . $voc->vid];
|
||||
if (!is_array($vterms)) $vterms = array($vterms);
|
||||
$terms = array_merge($terms, $vterms);
|
||||
}
|
||||
$terms = array_map('_custom_search_filter_keys', array_values(array_filter($terms)));
|
||||
// if one or more -Any- is selected, delete them
|
||||
while (($index = array_search('all', $terms)) !== FALSE) array_splice($terms, $index, 1);
|
||||
}
|
||||
|
||||
$search_types = module_implements('search');
|
||||
if (in_array(current($types), $search_types)) $type = current($types);
|
||||
else {
|
||||
if (trim($form_state['values']['custom_search_criteria_or']) != '') $keys .= ' ' . str_replace(' ', ' OR ', trim($form_state['values']['custom_search_criteria_or']));
|
||||
if (trim($form_state['values']['custom_search_criteria_negative']) != '') $keys .= ' -' . str_replace(' ', ' -', trim($form_state['values']['custom_search_criteria_negative']));
|
||||
if (trim($form_state['values']['custom_search_criteria_phrase']) != '') $keys .= ' "' . trim($form_state['values']['custom_search_criteria_phrase']) . '"';
|
||||
$original_keywords = $keys;
|
||||
if (count($types)) {
|
||||
// If a content type is selected, and it's not -Any-, search for that type.
|
||||
if (!in_array('all', $types)) $keys = search_query_insert($keys, 'type', implode(',', $types));
|
||||
// If -Any- is selected and -Any- is set to restrict the search, grab the content types.
|
||||
elseif (variable_get('custom_search_' . $delta . 'any_restricts', FALSE)) {
|
||||
$restricted_types = array_keys(array_filter(variable_get('custom_search_' . $delta . 'node_types', array())));
|
||||
$keys = search_query_insert($keys, 'type', implode(',', $restricted_types));
|
||||
}
|
||||
}
|
||||
if (module_exists('taxonomy') && count($terms)) {
|
||||
$keys = search_query_insert($keys, 'category', implode(',', $terms));
|
||||
}
|
||||
}
|
||||
|
||||
// Integrates other search modules
|
||||
if (module_exists('apachesolr_search') && variable_get('apachesolr_search_make_default', 0)) {
|
||||
$search_path = _custom_search_apachesolr_search(array(
|
||||
'keywords' => $original_keywords,
|
||||
'types' => $types,
|
||||
'terms' => (!empty($terms)) ? $terms : array(),
|
||||
));
|
||||
}
|
||||
elseif (module_exists('google_appliance')) {
|
||||
$search_path = _custom_search_google_appliance_search(array(
|
||||
'keys' => $keys,
|
||||
));
|
||||
}
|
||||
elseif (module_exists('luceneapi_node') && variable_get('luceneapi:default_search', 0)) {
|
||||
$search_path = _custom_search_lucenapi_search(array(
|
||||
'keywords' => $original_keywords,
|
||||
'types' => $types,
|
||||
'terms' => (!empty($terms)) ? $terms : array(),
|
||||
));
|
||||
}
|
||||
else {
|
||||
$search_path = array(
|
||||
'path' => 'search/' . $type . '/' . $keys,
|
||||
'query' => '',
|
||||
);
|
||||
}
|
||||
|
||||
// Build a custom path if needed
|
||||
if (isset($form_state['values']['custom_search_paths']) && $form_state['values']['custom_search_paths'] != '') {
|
||||
$custom_path = str_replace('[key]', $form_state['values'][$form_state['values']['form_id']], $form_state['values']['custom_search_paths']);
|
||||
if (strpos($form_state['values']['custom_search_paths'], '[terms]') !== FALSE) $custom_path = str_replace('[terms]', (count($terms)) ? implode($form_state['values']['custom_search_paths_terms_separator'], $terms) : '', $custom_path);
|
||||
$form_state['redirect'] = $custom_path;
|
||||
// check for external path. If not, add base path
|
||||
if (drupal_substr($custom_path, 0, 4) != 'http') $form_state['redirect'] = url($form_state['redirect'], array('absolute' => TRUE));
|
||||
}
|
||||
else $form_state['redirect'] = url($search_path['path'], array('query' => $search_path['query'], 'absolute' => TRUE));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Rewrite the sql query to exclude content types
|
||||
*/
|
||||
function custom_search_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
|
||||
if ($query == '' && $primary_table == 'n' && $primary_field = 'nid' && empty($args)) {
|
||||
$excluded_types = array_filter(variable_get('custom_search_' . variable_get('custom_search_delta', '') . 'node_types_excluded', array()));
|
||||
if (!empty($excluded_types)) {
|
||||
$where = " n.type NOT IN ('". join("','", $excluded_types) ."') ";
|
||||
return array('where' => $where);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_init().
|
||||
*/
|
||||
function custom_search_init() {
|
||||
if (user_access('use custom search')) {
|
||||
drupal_add_js(drupal_get_path('module', 'custom_search') . '/js/custom_search.js');
|
||||
drupal_add_js(array('custom_search' => array(
|
||||
'form_target' => variable_get('custom_search_target', '_self'),
|
||||
'solr' => (module_exists('apachesolr_search') && variable_get('apachesolr_search_make_default', 0)) ? 1 : 0,
|
||||
)), 'setting');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme().
|
||||
*/
|
||||
function custom_search_theme() {
|
||||
$path = drupal_get_path('module', 'custom_search') . '/theme';
|
||||
$custom_search_theme_array = array(
|
||||
'custom_search_javascript' => array('arguments' => array()),
|
||||
'custom_search_sort_form' => array(
|
||||
'path' => $path,
|
||||
'template' => 'custom_search-sort-form',
|
||||
'arguments' => array('form' => NULL),
|
||||
),
|
||||
'search_results' => array(
|
||||
'arguments' => array('results' => NULL, 'type' => NULL),
|
||||
'path' => $path,
|
||||
'file' => 'custom_search.pages.inc',
|
||||
'template' => 'custom_search-results',
|
||||
),
|
||||
'search_result' => array(
|
||||
'arguments' => array('result' => NULL, 'type' => NULL),
|
||||
'path' => $path,
|
||||
'file' => 'custom_search.pages.inc',
|
||||
'template' => 'custom_search-result',
|
||||
),
|
||||
);
|
||||
|
||||
// Panels integration
|
||||
$search_results_page_callback = menu_get_item('search/node/%menu_tail');
|
||||
if ($search_results_page_callback['page_callback'] == 'page_manager_search_page') {
|
||||
unset($custom_search_theme_array['search_results'], $custom_search_theme_array['search_result']);
|
||||
}
|
||||
|
||||
return $custom_search_theme_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the types.
|
||||
*/
|
||||
function _custom_search_filter_keys($val) {
|
||||
return (strlen($val) > 2 && $val[1] == '-') ? drupal_substr($val, 2) : $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the label by adding a class.
|
||||
*/
|
||||
function _custom_search_hide_label($content, $elements) {
|
||||
if (strpos($content, '<label class') !== FALSE) $content = str_replace('<label class="', '<label class="element-invisible ', $content);
|
||||
else $content = str_replace('<label', '<label class="element-invisible"', $content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to filter node_type array to only filter those that are configured in Custom Search Form
|
||||
*/
|
||||
function custom_search_filter_array($value = FALSE) {
|
||||
return $value !== 0;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Path generation for Apache Solr Search.
|
||||
*
|
||||
* Available vars:
|
||||
* $orginal_keywords: user input
|
||||
* $types: content types (machine names[])
|
||||
* $terms: taxonomy terms (tids[])
|
||||
* $keys: complete search phrase, as core would have done it
|
||||
*
|
||||
* To return:
|
||||
* the complete search path
|
||||
*
|
||||
*/
|
||||
|
||||
function _custom_search_apachesolr_search($variables) {
|
||||
$type = 'search/apachesolr_search/' . $variables['keywords'];
|
||||
$keys = array();
|
||||
|
||||
if (count($variables['types']) && !in_array('all', $variables['types'])) $keys[] = 'type:' . implode('%20type:', $variables['types']);
|
||||
|
||||
if (module_exists('taxonomy') && count($variables['terms'])) $keys[] = 'tid:' . implode('%20tid:', $variables['terms']);
|
||||
|
||||
$keys = 'filters=' . implode('%20', $keys);
|
||||
|
||||
return array('path' => $type, 'query' => $keys);
|
||||
}
|
311
sites/all/modules/custom_search/includes/forms.inc
Normal file
311
sites/all/modules/custom_search/includes/forms.inc
Normal file
|
@ -0,0 +1,311 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Image button form.
|
||||
*/
|
||||
function _custom_search_default_admin_form($delta = '') {
|
||||
if ($delta != '') $delta = 'blocks_' . $delta . '_';
|
||||
|
||||
// Labels & default text.
|
||||
$form['search_box'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Search box'),
|
||||
);
|
||||
$form['search_box']['custom_search_' . $delta . 'label_visibility'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display label'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'label_visibility', TRUE),
|
||||
);
|
||||
$form['search_box']['custom_search_' . $delta . 'label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Search box label'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT),
|
||||
'#description' => t('Enter the label text for the search box. The default value is "!default".', array('!default' => CUSTOM_SEARCH_LABEL_DEFAULT)),
|
||||
);
|
||||
$form['search_box']['custom_search_' . $delta . 'text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Search box default text'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'text', ''),
|
||||
'#description' => t('This will change the default text inside the search form. Leave blank for no text. This field is blank by default.'),
|
||||
);
|
||||
$form['search_box']['custom_search_' . $delta . 'size'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Search box size'),
|
||||
'#size' => 3,
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'size', CUSTOM_SEARCH_SIZE_DEFAULT),
|
||||
'#description' => t('The default value is "!default".', array('!default' => CUSTOM_SEARCH_SIZE_DEFAULT)),
|
||||
);
|
||||
$form['search_box']['custom_search_' . $delta . 'max_length'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Search box maximum length'),
|
||||
'#size' => 3,
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'max_length', CUSTOM_SEARCH_MAX_LENGTH_DEFAULT),
|
||||
'#description' => t('The default value is "!default".', array('!default' => CUSTOM_SEARCH_MAX_LENGTH_DEFAULT)),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
// Submit button.
|
||||
$form['submit_button'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Submit button'),
|
||||
);
|
||||
$form['submit_button']['custom_search_' . $delta . 'submit_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Submit button text'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT),
|
||||
'#description' => t('Enter the text for the submit button. Leave blank to hide it. The default value is "!default".', array('!default' => CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT)),
|
||||
);
|
||||
$form['submit_button']['custom_search_' . $delta . 'image_path'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Submit image path'),
|
||||
'#description' => t('The path to the file you would like to use as submit button instead of the default text button.'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'image_path', ''),
|
||||
);
|
||||
$form['submit_button']['custom_search_image'] = array(
|
||||
'#type' => 'file',
|
||||
'#title' => t('Submit image'),
|
||||
'#description' => t('If you don\'t have direct file access to the server, use this field to upload your image.'),
|
||||
);
|
||||
|
||||
// Criteria.
|
||||
$form['criteria'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Advanced search criteria'),
|
||||
);
|
||||
$form['criteria']['or'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Or'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['criteria']['or']['custom_search_' . $delta . 'criteria_or_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'criteria_or_display', FALSE),
|
||||
);
|
||||
$form['criteria']['or']['custom_search_' . $delta . 'criteria_or_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'criteria_or_label', CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT),
|
||||
'#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT)),
|
||||
);
|
||||
$form['criteria']['phrase'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Phrase'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['criteria']['phrase']['custom_search_' . $delta . 'criteria_phrase_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'criteria_phrase_display', FALSE),
|
||||
);
|
||||
$form['criteria']['phrase']['custom_search_' . $delta . 'criteria_phrase_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'criteria_phrase_label', CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT),
|
||||
'#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT)),
|
||||
);
|
||||
$form['criteria']['negative'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Negative'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['criteria']['negative']['custom_search_' . $delta . 'criteria_negative_display'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'criteria_negative_display', FALSE),
|
||||
);
|
||||
$form['criteria']['negative']['custom_search_' . $delta . 'criteria_negative_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT),
|
||||
'#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT)),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content admin form.
|
||||
*/
|
||||
function _custom_search_content_admin_form($delta = '') {
|
||||
if ($delta != '') $delta = 'blocks_' . $delta . '_';
|
||||
|
||||
$form['content_selector'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Content selector'),
|
||||
'#description' => t('Select the search types to present as search options in the search block. If none is selected, no selector will be displayed. <strong>Note</strong>: if there\'s only one type checked, the selector won\'t be displayed BUT only this type will be searched.'),
|
||||
);
|
||||
$form['content_selector']['custom_search_' . $delta . 'node_types'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Content types'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'node_types', array()),
|
||||
'#options' => node_get_types('names'),
|
||||
);
|
||||
// Other searches.
|
||||
$options = array();
|
||||
foreach (module_implements('search') as $module) {
|
||||
if ($module != 'node' && $name = module_invoke($module, 'search', 'name')) {
|
||||
$options[$module] = $name;
|
||||
}
|
||||
}
|
||||
if (count($options)) {
|
||||
$form['content_selector']['custom_search_' . $delta . 'other'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Other searches'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'other', array()),
|
||||
'#options' => $options,
|
||||
);
|
||||
}
|
||||
$form['content_selector']['custom_search_' . $delta . 'type_selector'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Selector type'),
|
||||
'#options' => array(
|
||||
'select' => t('Drop-down list'),
|
||||
'selectmultiple' => t('Drop-down list with multiple choices'),
|
||||
'radios' => t('Radio buttons'),
|
||||
'checkboxes' => t('Checkboxes'),
|
||||
),
|
||||
'#description' => t('Choose which selector type to use. Note: content types and other searches cannot be combined in a single search.'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'type_selector', 'select'),
|
||||
);
|
||||
$form['content_selector']['custom_search_' . $delta . 'type_selector_label_visibility'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display label'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'type_selector_label_visibility', TRUE),
|
||||
);
|
||||
$form['content_selector']['custom_search_' . $delta . 'type_selector_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label text'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT),
|
||||
'#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT)),
|
||||
);
|
||||
$form['content_selector']['any'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('-Any-'),
|
||||
);
|
||||
$form['content_selector']['any']['custom_search_' . $delta . 'type_selector_all'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('-Any content type- text'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT),
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Enter the text for "any content type" choice. The default value is "!default".', array('!default' => CUSTOM_SEARCH_ALL_TEXT_DEFAULT)),
|
||||
);
|
||||
$form['content_selector']['any']['custom_search_' . $delta . 'any_restricts'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Choosing -Any- restricts the search to the selected content types.'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'any_restricts', FALSE),
|
||||
'#description' => t('If not checked, choosing -Any- will search in all content types.'),
|
||||
);
|
||||
$form['content_selector']['any']['custom_search_' . $delta . 'any_force'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Force -Any- to be displayed.'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'any_force', FALSE),
|
||||
'#description' => t('When only one content type is selected, the default behaviour is to hide the selector. If you need the -Any- option to be displayed, check this.'),
|
||||
);
|
||||
|
||||
$form['custom_search_' . $delta . 'node_types_excluded'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Content exclusion'),
|
||||
'#description' => t('Select the content types you don\'t want to be displayed as results.'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'node_types_excluded', array()),
|
||||
'#options' => node_get_types('names'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom paths admin form.
|
||||
*/
|
||||
function _custom_search_custom_paths_admin_form($delta = '') {
|
||||
if ($delta != '') $delta = 'blocks_' . $delta . '_';
|
||||
$form['custom_search_paths_admin'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Custom search paths'),
|
||||
'#collapsed' => TRUE,
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
$form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Selector type'),
|
||||
'#options' => array(
|
||||
'select' => t('Drop-down list'),
|
||||
'radios' => t('Radio buttons'),
|
||||
),
|
||||
'#description' => t('Choose which selector type to use.'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'paths_selector', 'select'),
|
||||
);
|
||||
$form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector_label_visibility'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display label'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'paths_selector_label_visibility', TRUE),
|
||||
);
|
||||
$form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label text'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT),
|
||||
'#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT)),
|
||||
);
|
||||
$form['custom_search_paths_admin']['custom_search_' . $delta . 'paths'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Paths'),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'paths', ''),
|
||||
'#rows' => 3,
|
||||
'#description' => t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box. Ie: mysearch/[key]|My custom search label.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ordering admin form
|
||||
*/
|
||||
function _custom_search_ordering_admin_form($delta = '') {
|
||||
drupal_add_css(drupal_get_path('module', 'custom_search') . '/custom_search.css', 'module');
|
||||
|
||||
if ($delta != '') $delta = 'blocks_' . $delta . '_';
|
||||
$form['order'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Elements ordering'),
|
||||
'#description' => t('Order the form elements as you want them to be displayed. If you put elements in the Popup section, they will only appear when the search field is clicked.')
|
||||
);
|
||||
$form['order']['custom_search_' . $delta . 'order'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#theme' => 'custom_search_sort_form',
|
||||
);
|
||||
|
||||
$elements = array(
|
||||
'search_box' => array('title' => t('Search box'), 'default_weight' => -1),
|
||||
'criteria_or' => array('title' => t('Advanced search criterion: Or'), 'default_weight' => 6),
|
||||
'criteria_phrase' => array('title' => t('Advanced search criterion: Phrase'), 'default_weight' => 7),
|
||||
'criteria_negative' => array('title' => t('Advanced search criterion: Negative'), 'default_weight' => 8),
|
||||
'custom_paths' => array('title' => t('Custom search paths'), 'default_weight' => 9),
|
||||
'submit_button' => array('title' => t('Submit button'), 'default_weight' => 10),
|
||||
);
|
||||
if (count(array_filter(array_merge(variable_get('custom_search_' . $delta . 'node_types', array()), variable_get('custom_search_' . $delta . 'other', array())))))
|
||||
$elements['content_types'] = array('title' => t('Content Types'), 'default_weight' => 0);
|
||||
|
||||
foreach ($elements as $element => $data) {
|
||||
$form['order']['custom_search_' . $delta . 'order'][$element] = array(
|
||||
'#title' => $data['title'],
|
||||
'#weight' => variable_get('custom_search_' . $delta . $element . '_weight', $data['default_weight']),
|
||||
);
|
||||
$form['order']['custom_search_' . $delta . 'order'][$element]['sort'] = array(
|
||||
'#type' => 'weight',
|
||||
'#default_value' => variable_get('custom_search_' . $delta . $element . '_weight', $data['default_weight']),
|
||||
'#attributes' => array('class' => 'sort-select sort-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block')),
|
||||
);
|
||||
$form['order']['custom_search_' . $delta . 'order'][$element]['region'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'block' => t('Block'),
|
||||
'popup' => t('Popup')
|
||||
),
|
||||
'#default_value' => variable_get('custom_search_' . $delta . $element . '_region', 'block'),
|
||||
'#attributes' => array('class' => 'region-select region-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block')),
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Path generation for Google Appliance Search.
|
||||
*
|
||||
* Available vars:
|
||||
* $orginal_keywords: user input
|
||||
* $types: content types (machine names[])
|
||||
* $terms: taxonomy terms (tids[])
|
||||
* $keys: complete search phrase, as core would have done it
|
||||
*
|
||||
* To return:
|
||||
* the complete search path
|
||||
*
|
||||
*/
|
||||
|
||||
function _custom_search_google_appliance_search($variables) {
|
||||
$type = variable_get('google_appliance_default_search_path', 'google-appliance');
|
||||
return array('path' => $type . '/' . $variables['keys'], 'query' => '');
|
||||
}
|
33
sites/all/modules/custom_search/includes/luceneapi_node.inc
Normal file
33
sites/all/modules/custom_search/includes/luceneapi_node.inc
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Path generation for Lucene API Search.
|
||||
*
|
||||
* Available vars:
|
||||
* $orginal_keywords: user input
|
||||
* $types: content types (machine names[])
|
||||
* $terms: taxonomy terms (tids[])
|
||||
* $keys: complete search phrase, as core would have done it
|
||||
*
|
||||
* To return:
|
||||
* the complete search path
|
||||
*
|
||||
*/
|
||||
|
||||
function _custom_search_lucenapi_search($variables) {
|
||||
$type = 'search/' . variable_get('luceneapi:default_search', 0) . '/' . $variables['keywords'];
|
||||
$keys = array();
|
||||
|
||||
if (count($variables['types']) && !in_array('all', $variables['types'])) {
|
||||
foreach ($variables['types'] as $t) $keys[] = "type[$t]=$t";
|
||||
}
|
||||
|
||||
if (module_exists('taxonomy') && count($variables['terms'])) {
|
||||
foreach ($variables['terms'] as $t) $keys[] = "category[$t]=$t";
|
||||
}
|
||||
|
||||
$keys = implode('&', $keys);
|
||||
|
||||
return array('path' => $type, 'query' => $keys);
|
||||
}
|
113
sites/all/modules/custom_search/js/custom_search.js
Normal file
113
sites/all/modules/custom_search/js/custom_search.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
;(function($) {
|
||||
|
||||
Drupal.behaviors.custom_search = function (context) {
|
||||
|
||||
if (!Drupal.settings.custom_search.solr) {
|
||||
// Check if the search box is not empty on submit
|
||||
$('form.search-form', context).submit(function(){
|
||||
var box = $(this).find('input.custom-search-box');
|
||||
if (box.val() != undefined && (box.val() == '' || box.val() == $(this).find('input.default-text').val())) {
|
||||
$(this).find('input.custom-search-box').addClass('error');
|
||||
return false;
|
||||
}
|
||||
// If basic search is hidden, copy or value to the keys
|
||||
if ($(this).find('#edit-keys').parents('div.element-invisible').attr('class') == 'element-invisible') {
|
||||
$(this).find('#edit-keys').val($(this).find('#edit-or').val());
|
||||
$(this).find('#edit-or').val('');
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// Search from target
|
||||
$('form.search-form').attr('target', Drupal.settings.custom_search.form_target);
|
||||
|
||||
// Clear default text on focus, and put it back on blur. Also displays Popup.
|
||||
$('input.custom-search-box', context)
|
||||
.blur(function(e){
|
||||
var $this = $(this);
|
||||
var $parentForm = $this.parents('form');
|
||||
if ($this.val() == '') {
|
||||
$this.addClass('custom-search-default-value');
|
||||
$this.val($parentForm.find('input.default-text').val());
|
||||
}
|
||||
})
|
||||
.bind('click focus', function(e){
|
||||
var $this = $(this);
|
||||
var $parentForm = $this.parents('form');
|
||||
if ($this.val() == $parentForm.find('input.default-text').val()) $this.val('');
|
||||
$this.removeClass('custom-search-default-value');
|
||||
// check if there's something in the popup and displays it
|
||||
var popup = $parentForm.find('fieldset.custom_search-popup');
|
||||
if (popup.find('input,select').length && !popup.hasClass('opened')) popup.fadeIn().addClass('opened');
|
||||
e.stopPropagation();
|
||||
}
|
||||
);
|
||||
$(document).bind('click focus', function(){
|
||||
$('fieldset.custom_search-popup').hide().removeClass('opened');
|
||||
});
|
||||
|
||||
// Handle checkboxes
|
||||
$('.custom-search-selector input:checkbox', context).each(function(){
|
||||
var el = $(this);
|
||||
if (el.val() == 'c-all') {
|
||||
el.change(function(){
|
||||
$(this).parents('.custom-search-selector').find('input:checkbox[value!=c-all]').attr('checked', false);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (el.val().substr(0,2) == 'c-') {
|
||||
el.change(function(){
|
||||
$('.custom-search-selector input:checkbox').each(function(){
|
||||
if ($(this).val().substr(0,2) == 'o-') $(this).attr('checked', false);
|
||||
});
|
||||
$(this).parents('.custom-search-selector').find('input:checkbox[value=c-all]').attr('checked', false);
|
||||
});
|
||||
} else {
|
||||
el.change(function(){
|
||||
$(this).parents('.custom-search-selector').find('input:checkbox[value!='+el.val()+']').attr('checked', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Reselect types and terms in advanced search
|
||||
var edit_keys = $('#edit-keys').val();
|
||||
if(edit_keys) {
|
||||
// types
|
||||
var pos = edit_keys.indexOf('type:');
|
||||
if (pos) {
|
||||
var pos2 = edit_keys.indexOf(' ',pos);
|
||||
if (pos2==-1) pos2 = edit_keys.length;
|
||||
var types = edit_keys.substring(pos+5,pos2);
|
||||
types = types.split(',');
|
||||
for (var i=0; i<types.length; i++) {
|
||||
$('.search-form input:checkbox[value='+types[i]+']').attr('checked', true);
|
||||
}
|
||||
}
|
||||
// terms
|
||||
var pos = edit_keys.indexOf('category:');
|
||||
if (pos) {
|
||||
var pos2 = edit_keys.indexOf(' ',pos);
|
||||
if (pos2==-1) pos2 = edit_keys.length;
|
||||
var terms = edit_keys.substring(pos+9,pos2);
|
||||
terms = terms.split(',');
|
||||
for (var i=0; i<terms.length; i++) {
|
||||
$('.search-form option[value='+terms[i]+']').attr('selected', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var popup = $('fieldset.custom_search-popup:not(.custom_search-processed)', context).addClass("custom_search-processed");
|
||||
popup.click(function(e){
|
||||
e.stopPropagation();
|
||||
})
|
||||
popup.append('<a class="custom_search-popup-close" href="#">' + Drupal.t('Close') + '</a>');
|
||||
$('a.custom_search-popup-close').click(function(e){
|
||||
$('fieldset.custom_search-popup.opened').hide().removeClass('opened');
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}(jQuery));
|
92
sites/all/modules/custom_search/js/custom_search_sort.js
Normal file
92
sites/all/modules/custom_search/js/custom_search_sort.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
;(function($) {
|
||||
|
||||
/**
|
||||
* Move a block in the blocks table from one region to another via select list.
|
||||
*
|
||||
* This behavior is dependent on the tableDrag behavior, since it uses the
|
||||
* objects initialized in that behavior to update the row.
|
||||
*/
|
||||
Drupal.behaviors.customSearchSort = function(context) {
|
||||
var table = $('table#elements');
|
||||
var tableDrag = Drupal.tableDrag.elements; // Get the blocks tableDrag object.
|
||||
|
||||
// Add a handler for when a row is swapped, update empty regions.
|
||||
tableDrag.row.prototype.onSwap = function(swappedRow) {
|
||||
checkEmptyRegions(table, this);
|
||||
};
|
||||
|
||||
// Add a handler so when a row is dropped, update fields dropped into new regions.
|
||||
tableDrag.onDrop = function() {
|
||||
var dragObject = this;
|
||||
if ($(dragObject.rowObject.element).prev('tr').is('.region-message')) {
|
||||
var regionRow = $(dragObject.rowObject.element).prev('tr').get(0);
|
||||
var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
|
||||
var regionField = $('select.region-select', dragObject.rowObject.element);
|
||||
var weightField = $('select.sort-select', dragObject.rowObject.element);
|
||||
var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*sort-select-([^ ]+)([ ]+[^ ]+)*/, '$2');
|
||||
|
||||
if (!regionField.is('.region-select-'+ regionName)) {
|
||||
regionField.removeClass('region-select-' + oldRegionName).addClass('region-select-' + regionName);
|
||||
weightField.removeClass('sort-select-' + oldRegionName).addClass('sort-select-' + regionName);
|
||||
regionField.val(regionName);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Add the behavior to each region select list.
|
||||
$('select.region-select:not(.regionselect-processed)', context).each(function() {
|
||||
$(this).change(function(event) {
|
||||
// Make our new row and select field.
|
||||
var row = $(this).parents('tr:first');
|
||||
var select = $(this);
|
||||
tableDrag.rowObject = new tableDrag.row(row);
|
||||
|
||||
// Find the correct region and insert the row as the first in the region.
|
||||
$('tr.region-message', table).each(function() {
|
||||
if ($(this).is('.region-' + select[0].value + '-message')) {
|
||||
// Add the new row and remove the old one.
|
||||
$(this).after(row);
|
||||
// Manually update weights and restripe.
|
||||
tableDrag.updateFields(row.get(0));
|
||||
tableDrag.rowObject.changed = true;
|
||||
if (tableDrag.oldRowElement) {
|
||||
$(tableDrag.oldRowElement).removeClass('drag-previous');
|
||||
}
|
||||
tableDrag.oldRowElement = row.get(0);
|
||||
tableDrag.restripeTable();
|
||||
tableDrag.rowObject.markChanged();
|
||||
tableDrag.oldRowElement = row;
|
||||
$(row).addClass('drag-previous');
|
||||
}
|
||||
});
|
||||
|
||||
// Modify empty regions with added or removed fields.
|
||||
checkEmptyRegions(table, row);
|
||||
// Remove focus from selectbox.
|
||||
select.get(0).blur();
|
||||
});
|
||||
$(this).addClass('regionselect-processed');
|
||||
});
|
||||
|
||||
var checkEmptyRegions = function(table, rowObject) {
|
||||
$('tr.region-message', table).each(function() {
|
||||
// If the dragged row is in this region, but above the message row, swap it down one space.
|
||||
if ($(this).prev('tr').get(0) == rowObject.element) {
|
||||
// Prevent a recursion problem when using the keyboard to move rows up.
|
||||
if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
|
||||
rowObject.swap('after', this);
|
||||
}
|
||||
}
|
||||
// This region has become empty
|
||||
if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
|
||||
$(this).removeClass('region-populated').addClass('region-empty');
|
||||
}
|
||||
// This region has become populated.
|
||||
else if ($(this).is('.region-empty')) {
|
||||
$(this).removeClass('region-empty').addClass('region-populated');
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
}(jQuery));
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Admin settings for custom search
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_help().
|
||||
*/
|
||||
function custom_search_blocks_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/settings/custom_search/blocks':
|
||||
$output = t('If you want custom search blocks, enable them here. Then go to the <a href="@link">block page</a> to place them in a region.', array('@link' => url('admin/build/block')));
|
||||
break;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function custom_search_blocks_admin() {
|
||||
$form['custom_search_blocks_number'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Number of blocks'),
|
||||
'#size' => 2,
|
||||
'#default_value' => variable_get('custom_search_blocks_number', 1),
|
||||
);
|
||||
return system_settings_form($form);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
name = Custom Search Blocks
|
||||
description = Provides additional search blocks.
|
||||
core = 6.x
|
||||
package = Custom Search
|
||||
dependencies[] = custom_search
|
||||
; Information added by Drupal.org packaging script on 2014-04-23
|
||||
version = "6.x-1.13"
|
||||
core = "6.x"
|
||||
project = "custom_search"
|
||||
datestamp = "1398258531"
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update, and uninstall functions for the custom search module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function custom_search_blocks_install() {
|
||||
db_query("UPDATE {system} SET weight = 99 WHERE name = 'custom_search_blocks'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function custom_search_blocks_uninstall() {
|
||||
$blocks = variable_get('custom_search_blocks_number', 1);
|
||||
for ($delta=1 ; $delta<=$blocks ; $delta++) {
|
||||
variable_del('custom_search_blocks_' . $delta . '_label_visibility');
|
||||
variable_del('custom_search_blocks_' . $delta . '_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_text');
|
||||
variable_del('custom_search_blocks_' . $delta . '_size');
|
||||
variable_del('custom_search_blocks_' . $delta . '_max_length');
|
||||
variable_del('custom_search_blocks_' . $delta . '_submit_text');
|
||||
variable_del('custom_search_blocks_' . $delta . '_image_path');
|
||||
variable_del('custom_search_blocks_' . $delta . '_criteria_or_display');
|
||||
variable_del('custom_search_blocks_' . $delta . '_criteria_or_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_criteria_phrase_display');
|
||||
variable_del('custom_search_blocks_' . $delta . '_criteria_phrase_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_criteria_negative_display');
|
||||
variable_del('custom_search_blocks_' . $delta . '_criteria_negative_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_search_box_weight');
|
||||
variable_del('custom_search_blocks_' . $delta . '_content_types_weight');
|
||||
variable_del('custom_search_blocks_' . $delta . '_custom_paths_weight');
|
||||
variable_del('custom_search_blocks_' . $delta . '_submit_button_weight');
|
||||
variable_del('custom_search_blocks_' . $delta . '_search_box_region');
|
||||
variable_del('custom_search_blocks_' . $delta . '_content_types_region');
|
||||
variable_del('custom_search_blocks_' . $delta . '_custom_paths_region');
|
||||
variable_del('custom_search_blocks_' . $delta . '_submit_button_region');
|
||||
variable_del('custom_search_blocks_' . $delta . '_node_types');
|
||||
variable_del('custom_search_blocks_' . $delta . '_node_types_excluded');
|
||||
variable_del('custom_search_blocks_' . $delta . '_other');
|
||||
variable_del('custom_search_blocks_' . $delta . '_type_selector');
|
||||
variable_del('custom_search_blocks_' . $delta . '_type_selector_label_visibility');
|
||||
variable_del('custom_search_blocks_' . $delta . '_type_selector_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_type_selector_all');
|
||||
variable_del('custom_search_blocks_' . $delta . '_any_restricts');
|
||||
variable_del('custom_search_blocks_' . $delta . '_paths');
|
||||
variable_del('custom_search_blocks_' . $delta . '_paths_selector');
|
||||
variable_del('custom_search_blocks_' . $delta . '_paths_selector_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_paths_selector_label_visibility');
|
||||
if (module_exists('custom_search_taxonomy')) {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector');
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label_visibility');
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_all');
|
||||
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_weight');
|
||||
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_region');
|
||||
}
|
||||
variable_del('custom_search_blocks_' . $delta . '_paths_terms_separator');
|
||||
}
|
||||
}
|
||||
variable_del('custom_search_blocks_number');
|
||||
}
|
||||
|
||||
function custom_search_blocks_update_6100() {
|
||||
$ret = array();
|
||||
$blocks = variable_get('custom_search_blocks_number', 1);
|
||||
for ($delta=1 ; $delta<=$blocks ; $delta++) {
|
||||
variable_set('custom_search_blocks_' . $delta . '_submit_text', variable_get('custom_search_submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
|
||||
variable_set('custom_search_blocks_' . $delta . '_image_path', variable_get('custom_search_image_path', ''));
|
||||
variable_set('custom_search_blocks_' . $delta . '_criteria_or_display', variable_get('custom_search_criteria_or_display', FALSE));
|
||||
variable_set('custom_search_blocks_' . $delta . '_criteria_or_label', variable_get('custom_search_criteria_or_label', CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT));
|
||||
variable_set('custom_search_blocks_' . $delta . '_criteria_phrase_display', variable_get('custom_search_criteria_phrase_display', FALSE));
|
||||
variable_set('custom_search_blocks_' . $delta . '_criteria_phrase_label', variable_get('custom_search_criteria_phrase_label', CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT));
|
||||
variable_set('custom_search_blocks_' . $delta . '_criteria_negative_display', variable_get('custom_search_criteria_negative_display', FALSE));
|
||||
variable_set('custom_search_blocks_' . $delta . '_criteria_negative_label', variable_get('custom_search_criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT));
|
||||
}
|
||||
return $ret;
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Bring additional search blocks
|
||||
*
|
||||
* Adds node types and taxonomy options to the search form
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu().
|
||||
*/
|
||||
function custom_search_blocks_menu() {
|
||||
$items['admin/settings/custom_search/blocks'] = array(
|
||||
'title' => 'Search Blocks',
|
||||
'description' => 'Provide additional search blocks by content type.',
|
||||
'page arguments' => array('custom_search_blocks_admin'),
|
||||
'access arguments' => array('administer custom search blocks'),
|
||||
'file' => 'custom_search_blocks.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 3,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_perm().
|
||||
*/
|
||||
function custom_search_blocks_perm() {
|
||||
return array('administer custom search blocks', 'use custom search blocks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter().
|
||||
*/
|
||||
function custom_search_blocks_form_alter(&$form, $form_state, $form_id) {
|
||||
if ($form_id == 'block_admin_configure' && $form['module']['#value'] == 'custom_search_blocks') {
|
||||
// Needed to upload of file.
|
||||
$form['#attributes'] = array('enctype' => 'multipart/form-data');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_block() to provide additional blocks.
|
||||
*/
|
||||
function custom_search_blocks_block($op = 'list', $delta = 0, $edit = array()) {
|
||||
switch ($op) {
|
||||
|
||||
case 'configure':
|
||||
// Basic settings.
|
||||
$form = _custom_search_default_admin_form($delta);
|
||||
// Content.
|
||||
$form['content'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Content'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['content'] = array_merge($form['content'], _custom_search_content_admin_form($delta));
|
||||
// Custom search paths
|
||||
$form = array_merge($form, _custom_search_custom_paths_admin_form($delta));
|
||||
// Ordering
|
||||
$form = array_merge($form, _custom_search_ordering_admin_form($delta));
|
||||
$form['order']['#weight'] = 50;
|
||||
|
||||
return $form;
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
foreach ($edit as $key => $value) {
|
||||
if (drupal_substr($key, 0, 20) == 'custom_search_blocks') variable_set($key, $value);
|
||||
}
|
||||
foreach ($edit['custom_search_blocks_' . $delta . '_order'] as $key => $data) {
|
||||
variable_set('custom_search_blocks_' . $delta . '_' . $key . '_weight', $data['sort']);
|
||||
variable_set('custom_search_blocks_' . $delta . '_' . $key . '_region', $data['region']);
|
||||
}
|
||||
// Submit image?
|
||||
$directory_path = file_directory_path() . '/custom_search';
|
||||
file_check_directory($directory_path, FILE_CREATE_DIRECTORY);
|
||||
// Check for a new uploaded image.
|
||||
if ($file = file_save_upload('custom_search_image', array('file_validate_is_image' => array()))) {
|
||||
if (file_copy($file, $directory_path)) {
|
||||
variable_set('custom_search_blocks_' . $delta . '_image_path', $file->filepath);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
$blocks = array();
|
||||
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
|
||||
$blocks[$a]['info'] = "Custom Search $a";
|
||||
$blocks[$a]['cache'] = BLOCK_NO_CACHE;
|
||||
}
|
||||
return $blocks;
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
if (user_access('use custom search blocks')) {
|
||||
$block['content'] = drupal_get_form('custom_search_blocks_form_' . $delta, $delta);
|
||||
$block['subject'] = "Custom Search $delta";
|
||||
return $block;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_forms() to generate a unique form_id with the same form builder function
|
||||
*/
|
||||
function custom_search_blocks_forms($form_id, $args) {
|
||||
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
|
||||
$forms['custom_search_blocks_form_' . $a] = array(
|
||||
'callback' => 'custom_search_blocks_form',
|
||||
'callback arguments' => array($a),
|
||||
);
|
||||
}
|
||||
return $forms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Output a search form for the additional search blocks.
|
||||
*/
|
||||
function custom_search_blocks_form(&$form_state, $delta) {
|
||||
$form['custom_search_blocks_form_' . $delta] = array(
|
||||
'#type' => 'textfield',
|
||||
'#size' => 15,
|
||||
'#default_value' => '',
|
||||
'#attributes' => array('title' => t('Enter the terms you wish to search for.')),
|
||||
);
|
||||
|
||||
$form['delta'] = array('#type' => 'hidden', '#value' => $delta);
|
||||
$form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
|
||||
$form['#submit'][] = 'search_box_form_submit';
|
||||
|
||||
if (function_exists('apachesolr_autocomplete_variable_get_widget')) {
|
||||
// support for apachesolr_autocomplete module
|
||||
if (apachesolr_autocomplete_variable_get_widget() == 'custom') {
|
||||
$form['custom_search_blocks_form_' . $delta]['#attributes']['class'] = 'apachesolr-autocomplete unprocessed';
|
||||
}
|
||||
else {
|
||||
$form['custom_search_blocks_form_' . $delta]['#autocomplete_path'] = 'apachesolr_autocomplete';
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
name = Custom Search Internationalization
|
||||
description = Provides Internationalization to Custom Search.
|
||||
core = 6.x
|
||||
package = Custom Search
|
||||
dependencies[] = custom_search
|
||||
dependencies[] = i18nstrings
|
||||
; Information added by Drupal.org packaging script on 2014-04-23
|
||||
version = "6.x-1.13"
|
||||
core = "6.x"
|
||||
project = "custom_search"
|
||||
datestamp = "1398258531"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update, and uninstall functions for the custom search module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function custom_search_i18n_install() {
|
||||
db_query("UPDATE {system} SET weight = 110 WHERE name = 'custom_search_i18n'");
|
||||
}
|
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Brings Internationalization to Custom Search
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter().
|
||||
*/
|
||||
function custom_search_i18n_form_alter(&$form, $form_state, $form_id) {
|
||||
|
||||
// Filter the form_id value to identify all the custom blocks
|
||||
$form_id_processed = $form_id;
|
||||
$delta = '';
|
||||
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
|
||||
if ($form_id == 'custom_search_blocks_form_' . $a) {
|
||||
$form_id_processed = 'custom_search_blocks_form';
|
||||
$delta = 'blocks_' . $a . '_';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($form_id_processed) {
|
||||
case 'search_theme_form':
|
||||
case 'search_block_form':
|
||||
case 'custom_search_blocks_form':
|
||||
|
||||
if (user_access('use custom search')) {
|
||||
// Criteria
|
||||
$criteria = array('or', 'phrase', 'negative');
|
||||
foreach ($criteria as $c) {
|
||||
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_display', FALSE)) {
|
||||
if (variable_get('custom_search_' . $delta . 'criteria_' . $c . '_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_criteria_' . $c]['#title'] = i18nstrings('custom_search:criterion:1:' . $delta . $c .'_label', variable_get('custom_search_' . $delta . 'criteria_' . $c . '_label', constant('CUSTOM_SEARCH_CRITERIA_' . strtoupper($c) . '_LABEL_DEFAULT')));
|
||||
}
|
||||
else {
|
||||
$form['custom_search_criteria_' . $c]['#title'] = i18nstrings('custom_search:criterion:1:' . $delta . $c .'_label', variable_get('custom_search_' . $delta . 'criteria_' . $c . '_label', constant('CUSTOM_SEARCH_CRITERIA_' . strtoupper($c) . '_LABEL_DEFAULT')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Title
|
||||
$form[$form_id]['#title'] = i18nstrings('custom_search:common:1:' . $delta . 'label', variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT));
|
||||
|
||||
// Default text
|
||||
$form[$form_id]['#default_value'] = i18nstrings('custom_search:common:1:' . $delta . 'text', variable_get('custom_search_' . $delta . 'text', ''));
|
||||
$form['default_text']['#default_value'] = i18nstrings('custom_search:common:1:' . $delta . 'text', variable_get('custom_search_' . $delta . 'text', ''));
|
||||
|
||||
// Submit button
|
||||
$form['submit']['#value'] = i18nstrings('custom_search:common:1:' . $delta . 'submit_text', variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
|
||||
if ($form['submit']['#value'] == '') $form['submit']['#attributes'] = array('style' => 'display:none;');
|
||||
|
||||
// Type selector
|
||||
if ((!empty($form['custom_search_types']) && is_array($form['custom_search_types'])) || (!empty($form['popup']['custom_search_types']) && is_array($form['popup']['custom_search_types']))) {
|
||||
if (variable_get('custom_search_' . $delta . 'content_types_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_types']['#title'] = i18nstrings('custom_search:content_types:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
|
||||
if (array_key_exists('c-all', $form['popup']['custom_search_types']['#options'])) {
|
||||
$form['popup']['custom_search_types']['#options']['c-all'] = i18nstrings('custom_search:content_types:1:' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$form['custom_search_types']['#title'] = i18nstrings('custom_search:content_types:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
|
||||
if (array_key_exists('c-all', $form['custom_search_types']['#options'])) {
|
||||
$form['custom_search_types']['#options']['c-all'] = i18nstrings('custom_search:content_types:1:' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Taxonomy
|
||||
if (module_exists('custom_search_taxonomy')) {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
// Translate label and -all-
|
||||
foreach ($vocabularies as $voc) {
|
||||
if ((!empty($form['custom_search_vocabulary_' . $voc->vid]) && is_array($form['custom_search_vocabulary_' . $voc->vid])) || (!empty($form['popup']['custom_search_vocabulary_' . $voc->vid]) && is_array($form['popup']['custom_search_vocabulary_' . $voc->vid]))) {
|
||||
if (variable_get('custom_search_' . $delta . 'taxonomy'. $voc->vid . '_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#title'] = i18nstrings('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name));
|
||||
if (is_array($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']) && array_key_exists('c-all', $form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'])) {
|
||||
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']['c-all'] = i18nstrings('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$form['custom_search_vocabulary_' . $voc->vid]['#title'] = i18nstrings('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name));
|
||||
if (is_array($form['custom_search_vocabulary_' . $voc->vid]['#options']) && array_key_exists('c-all', $form['custom_search_vocabulary_' . $voc->vid]['#options'])) {
|
||||
$form['custom_search_vocabulary_' . $voc->vid]['#options']['c-all'] = i18nstrings('custom_search:vocabulary:' . $voc->vid . ':' . $delta . 'selector_all', variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Translate terms
|
||||
if (module_exists('i18ntaxonomy')) {
|
||||
foreach ($vocabularies as $voc) {
|
||||
if ((!empty($form['custom_search_vocabulary_' . $voc->vid]) && is_array($form['custom_search_vocabulary_' . $voc->vid]['#options'])) || (!empty($form['popup']['custom_search_vocabulary_' . $voc->vid]) && is_array($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options']))) {
|
||||
if (variable_get('custom_search_' . $delta . 'taxonomy'. $voc->vid . '_region', 'block') == 'popup') {
|
||||
foreach ($form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'] as $tid => $name) {
|
||||
if ($tid != 'c-all') {
|
||||
$real_tid = substr($tid, 2);
|
||||
$translated_term = i18nstrings('taxonomy:term:' . $real_tid . ':name', $name);
|
||||
$form['popup']['custom_search_vocabulary_' . $voc->vid]['#options'][$tid] = ($translated_term[0] != '-') ? str_repeat('-', _custom_search_i18n_term_depth($real_tid)) . ' ' . $translated_term : $translated_term ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($form['custom_search_vocabulary_' . $voc->vid]['#options'] as $tid => $name) {
|
||||
if ($tid != 'c-all') {
|
||||
$real_tid = substr($tid, 2);
|
||||
$translated_term = i18nstrings('taxonomy:term:' . $real_tid . ':name', $name);
|
||||
$form['custom_search_vocabulary_' . $voc->vid]['#options'][$tid] = ($translated_term[0] != '-') ? str_repeat('-', _custom_search_i18n_term_depth($real_tid)) . ' ' . $translated_term : $translated_term ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom Paths
|
||||
if ((!empty($form['custom_search_paths']) && is_array($form['custom_search_paths'])) || (!empty($form['popup']['custom_search_paths']) && is_array($form['popup']['custom_search_paths']))) {
|
||||
if (variable_get('custom_search_' . $delta . 'custom_paths_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_paths']['#title'] = i18nstrings('custom_search:paths:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
|
||||
}
|
||||
else {
|
||||
$form['custom_search_paths']['#title'] = i18nstrings('custom_search:paths:1:' . $delta . 'selector_label', variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'custom_search_admin': $form['#submit'][] = 'custom_search_i18n_admin_submit'; break;
|
||||
case 'custom_search_content_admin': $form['#submit'][] = 'custom_search_i18n_content_admin_submit'; break;
|
||||
case 'custom_search_taxonomy_admin': $form['#submit'][] = 'custom_search_i18n_taxonomy_admin_submit'; break;
|
||||
case 'custom_search_results_admin': $form['#submit'][] = 'custom_search_i18n_results_admin_submit'; break;
|
||||
case 'block_admin_configure': $form['#submit'][] = 'custom_search_i18n_block_admin_configure_submit'; break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function custom_search_i18n_preprocess_search_results(&$variables) {
|
||||
if (user_access('use custom search') && variable_get('custom_search_filter', 'disabled') != 'disabled') {
|
||||
$variables['filter-title'] = i18nstrings('custom_search:filter:1:label', variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callbacks for updating translations.
|
||||
*/
|
||||
function custom_search_i18n_admin_submit($form, &$form_state) {
|
||||
i18nstrings_update('custom_search:common:1:label', $form_state['values']['custom_search_label']);
|
||||
i18nstrings_update('custom_search:common:1:text', $form_state['values']['custom_search_text']);
|
||||
i18nstrings_update('custom_search:common:1:submit_text', $form_state['values']['custom_search_submit_text']);
|
||||
i18nstrings_update('custom_search:criterion:1:or_label', $form_state['values']['custom_search_criteria_or_label']);
|
||||
i18nstrings_update('custom_search:criterion:1:phrase_label', $form_state['values']['custom_search_criteria_phrase_label']);
|
||||
i18nstrings_update('custom_search:criterion:1:negative_label', $form_state['values']['custom_search_criteria_negative_label']);
|
||||
i18nstrings_update('custom_search:paths:1:selector_label', $form_state['values']['custom_search_paths_selector_label']);
|
||||
}
|
||||
|
||||
function custom_search_i18n_content_admin_submit($form, &$form_state) {
|
||||
i18nstrings_update('custom_search:content_types:1:selector_label', $form_state['values']['custom_search_type_selector_label']);
|
||||
i18nstrings_update('custom_search:content_types:1:selector_all', $form_state['values']['custom_search_type_selector_all']);
|
||||
}
|
||||
|
||||
function custom_search_i18n_taxonomy_admin_submit($form, &$form_state) {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':selector_label', $form_state['values']['custom_search_voc' . $voc->vid . '_selector_label']);
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':selector_all', $form_state['values']['custom_search_voc' . $voc->vid . '_selector_all']);
|
||||
}
|
||||
}
|
||||
|
||||
function custom_search_i18n_results_admin_submit($form, &$form_state) {
|
||||
i18nstrings_update('custom_search:filter:1:label', $form_state['values']['custom_search_filter_label']);
|
||||
}
|
||||
|
||||
function custom_search_i18n_block_admin_configure_submit($form, &$form_state) {
|
||||
$delta = $form_state['values']['delta'];
|
||||
i18nstrings_update('custom_search:common:1:blocks_' . $delta . '_label', $form_state['values']['custom_search_blocks_' . $delta . '_label']);
|
||||
i18nstrings_update('custom_search:common:1:blocks_' . $delta . '_text', $form_state['values']['custom_search_blocks_' . $delta . '_text']);
|
||||
i18nstrings_update('custom_search:common:1:blocks_' . $delta . '_submit_text', $form_state['values']['custom_search_blocks_' . $delta . '_submit_text']);
|
||||
i18nstrings_update('custom_search:criterion:1:blocks_' . $delta . '_or_label', $form_state['values']['custom_search_blocks_' . $delta . '_criteria_or_label']);
|
||||
i18nstrings_update('custom_search:criterion:1:blocks_' . $delta . '_phrase_label', $form_state['values']['custom_search_blocks_' . $delta . '_criteria_phrase_label']);
|
||||
i18nstrings_update('custom_search:criterion:1:blocks_' . $delta . '_negative_label', $form_state['values']['custom_search_blocks_' . $delta . '_criteria_negative_label']);
|
||||
i18nstrings_update('custom_search:content_types:1:blocks_' . $delta . '_selector_label', $form_state['values']['custom_search_blocks_' . $delta . '_type_selector_label']);
|
||||
i18nstrings_update('custom_search:content_types:1:blocks_' . $delta . '_selector_all', $form_state['values']['custom_search_blocks_' . $delta . '_type_selector_all']);
|
||||
i18nstrings_update('custom_search:paths:1:blocks_' . $delta . '_selector_label', $form_state['values']['custom_search_blocks_' . $delta . '_paths_selector_label']);
|
||||
if (module_exists('custom_search_taxonomy')) {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $delta . '_selector_label', $form_state['values']['custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label']);
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $delta . '_selector_all', $form_state['values']['custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_all']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_locale().
|
||||
*/
|
||||
function custom_search_i18n_locale($op = 'groups', $group = NULL) {
|
||||
switch ($op) {
|
||||
case 'groups':
|
||||
return array('custom_search' => t('Custom Search'));
|
||||
break;
|
||||
case 'info':
|
||||
$info['custom_search']['refresh callback'] = 'custom_search_i18n_locale_refresh';
|
||||
return $info;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function custom_search_i18n_locale_refresh() {
|
||||
i18nstrings_update('custom_search:common:1:label', variable_get('custom_search_label', CUSTOM_SEARCH_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:common:1:text', variable_get('custom_search_text', ''));
|
||||
i18nstrings_update('custom_search:common:1:submit_text', variable_get('custom_search_submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT));
|
||||
i18nstrings_update('custom_search:content_types:1:selector_label', variable_get('custom_search_type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:content_types:1:selector_all', variable_get('custom_search_type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
i18nstrings_update('custom_search:paths:1:selector_label', variable_get('custom_search_paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:criterion:1:or_label', variable_get('custom_search_criteria_or_label', CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:criterion:1:phrase_label', variable_get('custom_search_criteria_phrase_label', CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:criterion:1:negative_label', variable_get('custom_search_criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:filter:1:label', variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT));
|
||||
if (module_exists('custom_search_taxonomy')) {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':selector_label', variable_get('custom_search_voc' . $voc->vid . '_selector_label', $voc->name));
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':selector_all', variable_get('custom_search_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
if (module_exists('custom_search_blocks')) {
|
||||
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $a . '_selector_label', variable_get('custom_search_blocks_' . $a . '_voc' . $voc->vid . '_selector_label', $voc->name));
|
||||
i18nstrings_update('custom_search:vocabulary:' . $voc->vid . ':blocks_' . $a . '_selector_all', variable_get('custom_search_blocks_' . $a . '_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (module_exists('custom_search_blocks')) {
|
||||
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
|
||||
i18nstrings_update('custom_search:common:1:blocks_' . $a . '_label', variable_get('custom_search_blocks_' . $a . '_label', CUSTOM_SEARCH_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:common:1:blocks_' . $a . '_text', $form_state['values']['custom_search_blocks_' . $a . '_text']);
|
||||
i18nstrings_update('custom_search:common:1:blocks_' . $a . '_submit_text', $form_state['values']['custom_search_blocks_' . $a . '_submit_text']);
|
||||
i18nstrings_update('custom_search:criterion:1:blocks_' . $a . '_or_label', $form_state['values']['custom_search_blocks_' . $a . '_criteria_or_label']);
|
||||
i18nstrings_update('custom_search:criterion:1:blocks_' . $a . '_phrase_label', $form_state['values']['custom_search_blocks_' . $a . '_criteria_phrase_label']);
|
||||
i18nstrings_update('custom_search:criterion:1:blocks_' . $a . '_negative_label', $form_state['values']['custom_search_blocks_' . $a . '_criteria_negative_label']);
|
||||
i18nstrings_update('custom_search:content_types:1:blocks_' . $a . '_selector_label', variable_get('custom_search_blocks_' . $a . '_type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT));
|
||||
i18nstrings_update('custom_search:content_types:1:blocks_' . $a . '_selector_all', variable_get('custom_search_blocks_' . $a . '_type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT));
|
||||
i18nstrings_update('custom_search:paths:1:blocks_' . $a . '_selector_label', variable_get('custom_search_blocks_' . $a . '_paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT));
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function _custom_search_i18n_term_depth($tid) {
|
||||
$limit = 99;
|
||||
$depth = 0;
|
||||
while ($parent = db_result(db_query("SELECT parent FROM {term_hierarchy} WHERE tid=%d", $tid))) {
|
||||
$depth++;
|
||||
$tid = $parent;
|
||||
if ($depth > $limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $depth;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Admin settings for custom search taxonomy
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_help().
|
||||
*/
|
||||
function custom_search_taxonomy_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/settings/custom_search/taxonomy':
|
||||
$output = t('Select the vocabularies to present as search options in the search block. If none is selected, no selector will be displayed.');
|
||||
break;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function custom_search_taxonomy_admin() {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
if (count($vocabularies)) {
|
||||
$options = array();
|
||||
foreach ($vocabularies as $voc) {
|
||||
$form[$voc->name] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $voc->name,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => (variable_get('custom_search_voc' . $voc->vid . '_selector', 'disabled') == 'disabled') ? TRUE : FALSE,
|
||||
);
|
||||
$form[$voc->name]['custom_search_voc' . $voc->vid . '_selector'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Selector type'),
|
||||
'#options' => array(
|
||||
'disabled' => t('Disabled'),
|
||||
'select' => t('Drop-down list'),
|
||||
'selectmultiple' => t('Drop-down list with multiple choices'),
|
||||
'radios' => t('Radio buttons'),
|
||||
'checkboxes' => t('Checkboxes'),
|
||||
),
|
||||
'#description' => t('Choose which selector type to use.'),
|
||||
'#default_value' => variable_get('custom_search_voc' . $voc->vid . '_selector', 'disabled'),
|
||||
);
|
||||
if (module_exists('hs_taxonomy')) $form[$voc->name]['custom_search_voc' . $voc->vid . '_selector']['#options']['hierarchical_select'] = t('Hierarchical selector');
|
||||
$form[$voc->name]['custom_search_voc' . $voc->vid . '_selector_depth'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Depth'),
|
||||
'#size' => 2,
|
||||
'#default_value' => variable_get('custom_search_voc' . $voc->vid . '_selector_depth', 0),
|
||||
'#description' => t('Define the maximum depth of terms being displayed. The default value is "0" which disables the limit.'),
|
||||
);
|
||||
$form[$voc->name]['custom_search_voc' . $voc->vid . '_selector_label_visibility'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display label'),
|
||||
'#default_value' => variable_get('custom_search_voc' . $voc->vid . '_selector_label_visibility', TRUE),
|
||||
);
|
||||
$form[$voc->name]['custom_search_voc' . $voc->vid . '_selector_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label text'),
|
||||
'#default_value' => variable_get('custom_search_voc' . $voc->vid . '_selector_label', $voc->name),
|
||||
'#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => $voc->name)),
|
||||
);
|
||||
$form[$voc->name]['custom_search_voc' . $voc->vid . '_selector_all'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('-Any- text'),
|
||||
'#default_value' => variable_get('custom_search_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT),
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Enter the text for "any term" choice. The default value is "!default".', array('!default' => CUSTOM_SEARCH_ALL_TEXT_DEFAULT)),
|
||||
);
|
||||
}
|
||||
}
|
||||
return system_settings_form($form);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
name = Custom Search Taxonomy
|
||||
description = Adds taxonomy selectors to Custom Search.
|
||||
core = 6.x
|
||||
package = Custom Search
|
||||
dependencies[] = custom_search
|
||||
dependencies[] = taxonomy
|
||||
; Information added by Drupal.org packaging script on 2014-04-23
|
||||
version = "6.x-1.13"
|
||||
core = "6.x"
|
||||
project = "custom_search"
|
||||
datestamp = "1398258531"
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update, and uninstall functions for the custom search module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function custom_search_taxonomy_install() {
|
||||
db_query("UPDATE {system} SET weight = 101 WHERE name = 'custom_search_taxonomy'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function custom_search_taxonomy_uninstall() {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
variable_del('custom_search_voc' . $voc->vid . '_selector');
|
||||
variable_del('custom_search_voc' . $voc->vid . '_selector_depth');
|
||||
variable_del('custom_search_voc' . $voc->vid . '_selector_label_visibility');
|
||||
variable_del('custom_search_voc' . $voc->vid . '_selector_label');
|
||||
variable_del('custom_search_voc' . $voc->vid . '_selector_all');
|
||||
variable_del('custom_search_taxonomy' . $voc->vid . '_weight');
|
||||
variable_del('custom_search_taxonomy' . $voc->vid . '_region');
|
||||
if (module_exists('custom_search_blocks')) {
|
||||
$blocks = variable_get('custom_search_blocks_number', 1);
|
||||
for ($delta=1 ; $delta<=$blocks ; $delta++) {
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector');
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_depth');
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label_visibility');
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label');
|
||||
variable_del('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_all');
|
||||
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_weight');
|
||||
variable_del('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_region');
|
||||
variable_del('custom_search_blocks_' . $delta . '_paths_terms_separator');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Bring customizations to the default search box
|
||||
*
|
||||
* Adds taxonomy options to the search form
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_menu().
|
||||
*/
|
||||
function custom_search_taxonomy_menu() {
|
||||
$items['admin/settings/custom_search/taxonomy'] = array(
|
||||
'title' => 'Taxonomy',
|
||||
'description' => 'Select the vocabularies to present as search options in the search block.',
|
||||
'page arguments' => array('custom_search_taxonomy_admin'),
|
||||
'access arguments' => array('administer custom search'),
|
||||
'file' => 'custom_search_taxonomy.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 2,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter().
|
||||
*/
|
||||
function custom_search_taxonomy_form_alter(&$form, $form_state, $form_id) {
|
||||
|
||||
// Filter the form_id value to identify all the custom blocks
|
||||
$form_id_processed = $form_id;
|
||||
$delta = '';
|
||||
for ($a = 1 ; $a <= variable_get('custom_search_blocks_number', 1) ; $a++) {
|
||||
if ($form_id == 'custom_search_blocks_form_' . $a) {
|
||||
$form_id_processed = 'custom_search_blocks_form';
|
||||
$delta = 'blocks_' . $a . '_';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($form_id_processed) {
|
||||
|
||||
case 'search_theme_form':
|
||||
case 'search_block_form':
|
||||
case 'custom_search_blocks_form':
|
||||
|
||||
if (user_access('use custom search')) {
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
foreach ($vocabularies as $voc) {
|
||||
if (variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled') != 'disabled') {
|
||||
$options = array();
|
||||
$options['c-all'] = variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT);
|
||||
$vocabulary_depth = (!variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_depth', 0)) ? NULL : variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_depth', 0);
|
||||
$terms = taxonomy_get_tree($voc->vid, 0, -1, $vocabulary_depth);
|
||||
foreach ($terms as $term) {
|
||||
$options['c-' . $term->tid] = (drupal_substr(variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'disabled'), 0, 6) == 'select') ? str_repeat('-', $term->depth) . ' ' . $term->name : $term->name ;
|
||||
}
|
||||
$selector_type = variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector', 'select');
|
||||
if ($selector_type == 'selectmultiple') {
|
||||
$selector_type = 'select';
|
||||
$multiple = TRUE;
|
||||
}
|
||||
else $multiple = FALSE;
|
||||
$form['custom_search_vocabulary_' . $voc->vid] = array(
|
||||
'#type' => $selector_type,
|
||||
'#multiple' => $multiple,
|
||||
'#title' => variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label', $voc->name),
|
||||
'#options' => $options,
|
||||
'#default_value' => ($selector_type == 'checkboxes') ? array('c-all') : 'c-all',
|
||||
'#attributes' => ($selector_type != 'radios' && $selector_type != 'checkboxes') ? array('class' => 'custom-search-selector custom-search-vocabulary custom-search-vocabulary-' . $voc->vid) : array(),
|
||||
'#prefix' => ($selector_type == 'radios' || $selector_type == 'checkboxes') ? '<div class="custom-search-selector custom-search-vocabulary custom-search-vocabulary-' . $voc->vid . '">' : '',
|
||||
'#suffix' => ($selector_type == 'radios' || $selector_type == 'checkboxes') ? '</div>' : '',
|
||||
'#weight' => variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_weight', 2),
|
||||
);
|
||||
|
||||
if ($selector_type == "hierarchical_select") {
|
||||
$form['custom_search_vocabulary_' . $voc->vid]['#config'] = array (
|
||||
'module' => 'hs_taxonomy',
|
||||
'params' => array('vid' => $voc->vid),
|
||||
);
|
||||
unset($form['custom_search_vocabulary_' . $voc->vid]['#options']);
|
||||
$form['#after_build'][] = 'hierarchical_select_after_build';
|
||||
}
|
||||
|
||||
if (variable_get('custom_search_' . $delta . 'taxonomy' . $voc->vid . '_region', 'block') == 'popup') {
|
||||
$form['popup']['custom_search_vocabulary_' . $voc->vid] = $form['custom_search_vocabulary_' . $voc->vid];
|
||||
unset($form['custom_search_vocabulary_' . $voc->vid]);
|
||||
}
|
||||
if (!variable_get('custom_search_' . $delta . 'voc' . $voc->vid . '_selector_label_visibility', TRUE)) $form['custom_search_vocabulary_' . $voc->vid]['#post_render'] = array('_custom_search_hide_label');
|
||||
}
|
||||
}
|
||||
|
||||
// Custom paths
|
||||
if (variable_get('custom_search_' . $delta . 'paths', '') != '') {
|
||||
$form['custom_search_paths_terms_separator'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => variable_get('custom_search_' . $delta . 'paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'block_admin_configure':
|
||||
if (isset($form['module']) && $form['module']['#value'] == 'custom_search_blocks') {
|
||||
|
||||
$delta = $form['delta']['#value'];
|
||||
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
if (count($vocabularies)) {
|
||||
$form['block_settings']['taxonomy'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Taxonomy'),
|
||||
'#description' => t('Select the vocabularies to present as search options in the search block. If none is selected, no selector will be displayed.'),
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
$w = 1;
|
||||
$collapsed = TRUE;
|
||||
foreach ($vocabularies as $voc) {
|
||||
// Selectors
|
||||
if (variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector', 'disabled') != 'disabled') {
|
||||
$collapsed = FALSE;
|
||||
$voc_collapsed = FALSE;
|
||||
}
|
||||
else $voc_collapsed = TRUE;
|
||||
$form['block_settings']['taxonomy'][$voc->name] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => check_plain($voc->name),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => $voc_collapsed,
|
||||
);
|
||||
$form['block_settings']['taxonomy'][$voc->name]['custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Selector type'),
|
||||
'#options' => array(
|
||||
'disabled' => t('Disabled'),
|
||||
'select' => t('Drop-down list'),
|
||||
'selectmultiple' => t('Drop-down list with multiple choices'),
|
||||
'radios' => t('Radio buttons'),
|
||||
'checkboxes' => t('Checkboxes'),
|
||||
),
|
||||
'#description' => t('Choose which selector type to use.'),
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector', 'disabled'),
|
||||
);
|
||||
$form['block_settings']['taxonomy'][$voc->name]['custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_depth'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Depth'),
|
||||
'#size' => 2,
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_depth', 0),
|
||||
'#description' => t('Define the maximum depth of terms being displayed. The default value is "0" which disables the limit.'),
|
||||
);
|
||||
$form['block_settings']['taxonomy'][$voc->name]['custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label_visibility'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display label'),
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label_visibility', TRUE),
|
||||
);
|
||||
$form['block_settings']['taxonomy'][$voc->name]['custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label text'),
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_label', $voc->name),
|
||||
'#description' => t('Enter the label text for the selector. The default value is "@default".', array('@default' => $voc->name)),
|
||||
);
|
||||
$form['block_settings']['taxonomy'][$voc->name]['custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_all'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('-Any- text'),
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_voc' . $voc->vid . '_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT),
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Enter the text for "any term" choice. The default value is "!default".', array('!default' => CUSTOM_SEARCH_ALL_TEXT_DEFAULT)),
|
||||
);
|
||||
// Ordering
|
||||
$form['block_settings']['order']['custom_search_blocks_' . $delta . '_order']['taxonomy' . $voc->vid] = array(
|
||||
'#title' => t('Taxonomy') . ': ' . $voc->name,
|
||||
'#weight' => variable_get('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_weight', $w),
|
||||
);
|
||||
$form['block_settings']['order']['custom_search_blocks_' . $delta . '_order']['taxonomy' . $voc->vid]['sort'] = array(
|
||||
'#type' => 'weight',
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_weight', $w),
|
||||
'#attributes' => array('class' => 'sort-select sort-select-' . variable_get('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_region', 'block')),
|
||||
);
|
||||
$form['block_settings']['order']['custom_search_blocks_' . $delta . '_order']['taxonomy' . $voc->vid]['region'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'block' => t('Block'),
|
||||
'popup' => t('Popup')
|
||||
),
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_region', 'block'),
|
||||
'#attributes' => array('class' => 'region-select region-select-' . variable_get('custom_search_blocks_' . $delta . '_taxonomy' . $voc->vid . '_region', 'block')),
|
||||
);
|
||||
$w++;
|
||||
}
|
||||
$form['block_settings']['taxonomy']['#collapsed'] = $collapsed;
|
||||
}
|
||||
|
||||
$form['block_settings']['custom_search_paths_admin']['custom_search_blocks_' . $delta . '_paths']['#description'] = t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box, and the [terms] token will be replaced by the selected taxonomy term id(s). Ie: mysearch/[key]/[terms]|My custom search label.');
|
||||
$form['block_settings']['custom_search_paths_admin']['custom_search_blocks_' . $delta . '_paths_terms_separator'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Taxonomy terms separator'),
|
||||
'#default_value' => variable_get('custom_search_blocks_' . $delta . '_paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
|
||||
'#size' => 2
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'custom_search_admin':
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
$w = 1;
|
||||
foreach ($vocabularies as $voc) {
|
||||
$form['order']['custom_search_order']['taxonomy' . $voc->vid] = array(
|
||||
'#title' => t('Taxonomy') . ': ' . check_plain($voc->name),
|
||||
'#weight' => variable_get('custom_search_taxonomy' . $voc->vid . '_weight', $w),
|
||||
);
|
||||
$form['order']['custom_search_order']['taxonomy' . $voc->vid]['sort'] = array(
|
||||
'#type' => 'weight',
|
||||
'#default_value' => variable_get('custom_search_taxonomy' . $voc->vid . '_weight', $w),
|
||||
'#attributes' => array('class' => 'sort-select sort-select-' . variable_get('custom_search_taxonomy' . $voc->vid . '_region', 'block')),
|
||||
);
|
||||
$form['order']['custom_search_order']['taxonomy' . $voc->vid]['region'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'block' => t('Block'),
|
||||
'popup' => t('Popup')
|
||||
),
|
||||
'#default_value' => variable_get('custom_search_taxonomy' . $voc->vid . '_region', 'block'),
|
||||
'#attributes' => array('class' => 'region-select region-select-' . variable_get('custom_search_taxonomy' . $voc->vid . '_region', 'block')),
|
||||
);
|
||||
$w++;
|
||||
}
|
||||
$form['custom_search_paths_admin']['custom_search_paths']['#description'] = t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box, and the [terms] token will be replaced by the selected taxonomy term id(s). Ie: mysearch/[key]/[terms]|My custom search label.');
|
||||
$form['custom_search_paths_admin']['custom_search_paths_terms_separator'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Taxonomy terms separator'),
|
||||
'#default_value' => variable_get('custom_search_paths_terms_separator', CUSTOM_SEARCH_PATHS_TERMS_SEPARATOR_DEFAULT),
|
||||
'#size' => 2
|
||||
);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file custom_search-result.tpl.php
|
||||
* Theme implementation for displaying a single search result.
|
||||
*
|
||||
* This template renders a single search result and is collected into
|
||||
* custom_search-results.tpl.php. This and the parent template are
|
||||
* dependent to one another sharing the markup for definition lists.
|
||||
*
|
||||
* Available variables:
|
||||
* - $url: URL of the result.
|
||||
* - $title: Title of the result.
|
||||
* - $snippet: A small preview of the result. Does not apply to user searches.
|
||||
* - $info: String of all the meta information ready for print. Does not apply
|
||||
* to user searches.
|
||||
* - $info_split: Contains same data as $info, split into a keyed array.
|
||||
* - $type: The type of search, e.g., "node" or "user".
|
||||
*
|
||||
* Default keys within $info_split:
|
||||
* - $info_split['type']: Node type.
|
||||
* - $info_split['user']: Author of the node linked to users profile. Depends
|
||||
* on permission.
|
||||
* - $info_split['date']: Last update of the node. Short formatted.
|
||||
* - $info_split['comment']: Number of comments output as "% comments", %
|
||||
* being the count. Depends on comment.module.
|
||||
* - $info_split['upload']: Number of attachments output as "% attachments", %
|
||||
* being the count. Depends on upload.module.
|
||||
*
|
||||
* Since $info_split is keyed, a direct print of the item is possible.
|
||||
* This array does not apply to user searches so it is recommended to check
|
||||
* for their existance before printing. The default keys of 'type', 'user' and
|
||||
* 'date' always exist for node searches. Modules may provide other data.
|
||||
*
|
||||
* <?php if (isset($info_split['comment'])) : ?>
|
||||
* <span class="info-comment">
|
||||
* <?php print $info_split['comment']; ?>
|
||||
* </span>
|
||||
* <?php endif; ?>
|
||||
*
|
||||
* To check for all available data within $info_split, use the code below.
|
||||
*
|
||||
* <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
|
||||
*
|
||||
* @see template_preprocess_custom_search_result()
|
||||
*/
|
||||
?>
|
||||
<dt class="title">
|
||||
<a href="<?php print $url; ?>"><?php print $title; ?></a>
|
||||
</dt>
|
||||
<dd>
|
||||
<?php if ($snippet) : ?>
|
||||
<p class="search-snippet"><?php print $snippet; ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ($info) : ?>
|
||||
<p class="search-info"><?php print $info; ?></p>
|
||||
<?php endif; ?>
|
||||
</dd>
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file custom_search-results.tpl.php
|
||||
* Theme implementation for displaying search results.
|
||||
*
|
||||
* This template collects each invocation of theme_search_result(). This and
|
||||
* the child template are dependant to one another sharing the markup for
|
||||
* definition lists.
|
||||
*
|
||||
* Note that modules may implement their own search type and theme function
|
||||
* completely bypassing this template.
|
||||
*
|
||||
* Available variables:
|
||||
* - $search_results: All results as it is rendered through
|
||||
* search-result.tpl.php
|
||||
* - $type: The type of search, e.g., "node" or "user".
|
||||
* - $filter: Rendered content types filter
|
||||
* - $filter_positon: above/below/disabled
|
||||
*
|
||||
* @see template_preprocess_custom_search_results()
|
||||
*/
|
||||
?>
|
||||
<?php if (isset($filter) && $filter != '' && $filter_position == 'above') { ?>
|
||||
<div class="custom-search-filter">
|
||||
<?php print $filter; ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<dl class="search-results <?php print $type; ?>-results">
|
||||
<?php print $search_results; ?>
|
||||
</dl>
|
||||
<?php if (isset($filter) && $filter != '' && $filter_position == 'below') { ?>
|
||||
<div class="custom-search-filter">
|
||||
<?php print $filter; ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php print $pager; ?>
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file custom_search-order-form.tpl.php
|
||||
* Default theme implementation to configure search form elements.
|
||||
*/
|
||||
|
||||
$element_regions = array(
|
||||
'block' => array('title' => t('Block'), 'count' => 0),
|
||||
'popup' => array('title' => t('Popup'), 'count' => 0),
|
||||
);
|
||||
foreach (element_children($form) as $element) $element_regions[$form[$element]['region']['#value']]['count']++;
|
||||
|
||||
// Add table javascript.
|
||||
drupal_add_js('misc/tableheader.js');
|
||||
drupal_add_js(drupal_get_path('module', 'custom_search') .'/js/custom_search_sort.js');
|
||||
foreach ($element_regions as $region => $title) {
|
||||
drupal_add_tabledrag('elements', 'match', 'sibling', 'region-select', 'region-select-'. $region, NULL, FALSE);
|
||||
drupal_add_tabledrag('elements', 'order', 'sibling', 'sort-select', 'sort-select-'. $region);
|
||||
}
|
||||
?>
|
||||
<table id="elements" class="sticky-enabled">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php print t('Element'); ?></th>
|
||||
<th><?php print t('Region'); ?></th>
|
||||
<th><?php print t('Weight'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $row = 0; ?>
|
||||
<?php foreach ($element_regions as $region => $region_data): ?>
|
||||
<tr class="region region-<?php print $region?>">
|
||||
<td colspan="3" class="region"><?php print $region_data['title']; ?></td>
|
||||
</tr>
|
||||
<tr class="region-message region-<?php print $region?>-message <?php print((!$region_data['count']) ? 'region-empty' : 'region-populated'); ?>">
|
||||
<td colspan="3"><em><?php print t('No elements in this region'); ?></em></td>
|
||||
</tr>
|
||||
<?php foreach (element_children($form) as $element):
|
||||
$data = $form[$element];
|
||||
if ($data['region']['#value'] == $region): ?>
|
||||
<tr class="draggable <?php print $row % 2 == 0 ? 'odd' : 'even'; ?>">
|
||||
<td class="element"><?php print $data['#title']; ?></td>
|
||||
<td><?php print drupal_render($data['region']); ?></td>
|
||||
<td><?php print drupal_render($data['sort']); ?></td>
|
||||
</tr>
|
||||
<?php $row++; ?>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* User page callbacks for the custom_search module.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Presents links to filter the search results.
|
||||
*/
|
||||
function custom_search_preprocess_search_results(&$variables) {
|
||||
if ($variables['type'] == 'node') {
|
||||
$variables['filter_position'] = variable_get('custom_search_filter', 'disabled');
|
||||
// save # of results for collapsing advanced search
|
||||
$GLOBALS['custom_search_nb_results'] = count($variables['results']);
|
||||
// generate the filter
|
||||
if (user_access('use custom search') && $variables['filter_position'] != 'disabled') {
|
||||
// Get search words (minus type:node_type)
|
||||
$keys = search_get_keys();
|
||||
if (strpos($keys, 'type:') !== FALSE) {
|
||||
$keys = drupal_substr($keys, 0, strpos($keys, 'type:')-1);
|
||||
}
|
||||
// Get Custom Search authorized types
|
||||
$searchable_node_types = variable_get('custom_search_node_types', array());
|
||||
$searchable_node_types = array_keys(array_filter($searchable_node_types, 'custom_search_filter_array'));
|
||||
if (!count($searchable_node_types)) $searchable_node_types = array_keys(node_get_types('names'));
|
||||
$node_types = db_query("SELECT type, name FROM {node_type} WHERE type IN (" . db_placeholders($searchable_node_types, 'varchar') . ")", $searchable_node_types);
|
||||
// Build menu
|
||||
$items = array();
|
||||
$items[] = l(variable_get('custom_search_type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT), 'search/node/' . $keys);
|
||||
while ($node_type = db_fetch_array($node_types)) {
|
||||
// count # of results per type
|
||||
$nbresults = 0;
|
||||
foreach ($variables['results'] as $result) {
|
||||
if ($result['node']->type == $node_type['type']) $nbresults++;
|
||||
}
|
||||
if ($nbresults) $items[] = l($node_type['name'], 'search/node/' . $keys . ' type:' . $node_type['type']);
|
||||
}
|
||||
if (!isset($variables['filter-title'])) {
|
||||
$variables['filter-title'] = filter_xss(variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT));
|
||||
}
|
||||
if (count($items) > 2) $variables['filter'] = theme('item_list', $items, $variables['filter-title']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Customisation of the results info.
|
||||
*/
|
||||
function custom_search_preprocess_search_result(&$variables) {
|
||||
// used to identify the correct info string
|
||||
$comment_str = preg_replace("/[0-9] (\b[a-z]*\b).*/", "$1", t('1 comment'));
|
||||
$attachment_str = preg_replace("/@*[a-z0-9]* (\b[a-z]*\b).*/", "$1", t('1 attachment'));
|
||||
|
||||
$infos = array();
|
||||
if (isset($variables['info_split'])) {
|
||||
foreach ($variables['info_split'] as $key => $info) {
|
||||
if (!is_numeric($key)) {
|
||||
if (variable_get('custom_search_results_info_' . $key, TRUE)) array_push($infos, $info);
|
||||
}
|
||||
else {
|
||||
if (variable_get('custom_search_results_info_comment', TRUE) && !empty($comment_str) && strpos($info, $comment_str) !== FALSE) array_push($infos, $info);
|
||||
if (variable_get('custom_search_results_info_upload', TRUE) && !empty($attachment_str) && strpos($info, $attachment_str) !== FALSE) array_push($infos, $info);
|
||||
}
|
||||
}
|
||||
}
|
||||
$variables['info'] = implode(' - ', $infos);
|
||||
}
|
Reference in a new issue