Skip to content
Snippets Groups Projects
Commit a31794e6 authored by Tim Steiner's avatar Tim Steiner
Browse files

[gh-66] Merging from testing into staging

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@500 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 7dde1909
No related branches found
No related tags found
No related merge requests found
Showing
with 6372 additions and 0 deletions
$Id: API.txt,v 1.10 2011/01/13 03:27:24 davereid Exp $
This document explains how to provide "Pathauto integration" in a
module. You need this if you would like to provide additional tokens
or if your module has paths and you wish to have them automatically
aliased. The simplest integration is just to provide tokens so we
cover that first. More advanced integration requires an
implementation of hook_pathauto to provide a settings form.
It may be helpful to review some examples of integration from the
pathauto_node.inc, pathauto_taxonomy.inc, and pathauto_user.inc files.
==================
1 - Providing additional tokens
==================
If all you want is to enable tokens for your module you will simply
need to implement two functions:
hook_token_values
hook_token_list
See the token.module and it's API.txt for more information about this
process.
If the token is intended to generate a path expected to contain slashes,
the token name must end in 'path', 'path-raw' or 'alias'. This indicates to
Pathauto that the slashes should not be removed from the replacement value.
When an object is created (whether it is a node or a user or a
taxonomy term) the data that Pathauto hands to the token_values in the
$object is in a specific format. This is the format that most people
write code to handle. However, during edits and bulk updates the data
may be in a totally different format. So, if you are writing a
hook_token_values implementation to add special tokens, be sure to
test creation, edit, and bulk update cases to make sure your code will
handle it.
==================
2 - Settings hook - To create aliases for your module
==================
You must implement hook_pathauto($op), where $op is always (at this
time) 'settings'. Return an object (NOT an array) containing the
following members, which will be used by pathauto to build a group
of settings for your module and define the variables for saving your
settings:
module - The name of your module (e.g., 'node')
groupheader - The translated label for the settings group (e.g.,
t('Content path settings')
patterndescr - The translated label for the default pattern (e.g.,
t('Default path pattern (applies to all content types with blank patterns below)')
patterndefault - A translated default pattern (e.g., t('[cat]/[title].html'))
token_type - The token type (e.g. 'node', 'user') that can be used.
patternitems - For modules which need to express multiple patterns
(for example, the node module supports a separate pattern for each
content type), an array whose keys consist of identifiers for each
pattern (e.g., the content type name) and values consist of the
translated label for the pattern
supportsfeeds - Modules which support RSS feeds should set this to the
string that's appended to a path for its feed (usually 'feed') , so
when administrators enable "Create feed aliases" an alias for this
content type's feed will be generated in addition to the base alias.
bulkname - For modules which support a bulk update operation, the
translated label for the action (e.g., t('Bulk update content paths'))
bulkdescr - For modules which support a bulk update operation, a
translated, more thorough description of what the operation will do
(e.g., t('Generate aliases for all existing content items which do not already have aliases.'))
==================
2 - $alias = pathauto_create_alias($module, $op, $placeholders, $src, $type=NULL)
==================
At the appropriate time (usually when a new item is being created for
which a generated alias is desired), call pathauto_create_alias() to
generate and create the alias. See the user, taxonomy, and nodeapi hook
implementations in pathauto.module for examples.
$module - The name of your module (e.g., 'node')
$op - Operation being performed on the item ('insert', 'update', or
'bulkupdate')
$placeholders - An array whose keys consist of the translated placeholders
which appear in patterns and values are the "clean" values to be
substituted into the pattern. Call pathauto_cleanstring() on any
values which you do not know to be purely alphanumeric, to substitute
any non-alphanumerics with the user's designated separator. Note that
if the pattern has multiple slash-separated components (e.g., [term:path]),
pathauto_cleanstring() should be called for each component, not the
complete string.
Example: $placeholders[t('[title]')] = pathauto_cleanstring($node->title);
$src - The "real" URI of the content to be aliased (e.g., "node/$node->nid")
$type - For modules which provided patternitems in hook_autopath(),
the relevant identifier for the specific item to be aliased (e.g.,
$node->type)
pathauto_create_alias() returns the alias that was created.
==================
3 - Bulk update function
==================
If a module supports bulk updating of aliases, it must provide a
function of this form, to be called by pathauto when the corresponding
checkbox is selected and the settings page submitted:
function <module>_pathauto_bulkupdate()
The function should iterate over the content items controlled by the
module, calling pathauto_create_alias() for each one. It is
recommended that the function report on its success (e.g., with a
count of created aliases) via drupal_set_message().
==================
4 - Bulk delete hook_path_alias_types()
==================
For modules that create new types of pages that can be aliased with pathauto, a
hook implementation is needed to allow the user to delete them all at once.
function hook_path_alias_types()
This hook returns an array whose keys match the beginning of the source paths
(e.g.: "node/", "user/", etc.) and whose values describe the type of page (e.g.:
"content", "users"). Like all displayed strings, these descriptionsshould be
localized with t(). Use % to match interior pieces of a path; "user/%/track". This
is a database wildcard, so be careful.
==================
Modules that extend node and/or taxonomy
==================
NOTE: this is basically not true any more. If you feel you need this file an issue.
Many contributed Drupal modules extend the core node and taxonomy
modules. To extend pathauto patterns to support their extensions, they
may implement the pathauto_node and pathauto_taxonomy hooks.
To do so, implement the function <modulename>_pathauto_node (or _taxonomy),
accepting the arguments $op and $node (or $term). Two operations are
supported:
$op = 'placeholders' - return an array keyed on placeholder strings
(e.g., t('[eventyyyy]')) valued with descriptions (e.g. t('The year the
event starts.')).
$op = 'values' - return an array keyed on placeholder strings, valued
with the "clean" actual value for the passed node or category (e.g.,
pathauto_cleanstring(date('M', $eventstart)));
See contrib/pathauto_node_event.inc for an example of extending node
patterns.
**Installation:
Pathauto is an extension to the path module, which must be enabled.
Pathauto also relies on the Token module, which must be downloaded and
enabled separately.
1. Unpack the Pathauto folder and contents in the appropriate modules
directory of your Drupal installation. This is probably
sites/all/modules/
2. Enable the Pathauto module in the administration tools.
3. If you're not using Drupal's default administrative account, make
sure "administer pathauto" is enabled through access control administration.
4. Visit the Pathauto settings page and make appropriate configurations
For 5.x: Administer > Site configuration > Pathauto
For 6.x: Administer > Site building > URL alias > Automated alias settings
**Transliteration support:
If you desire transliteration support in the creation of URLs (e.g. the
replacement of Á with A) then you will need to install the Transliteration
module, which can be found at http://drupal.org/project/transliteration
Once you've installed and enabled the module, simply go to
admin/config/search/path/settings and check the "Transliterate prior to
creating alias" box and path aliases should now be transliterated automagically.
**Upgrading from previous versions:
If you are upgrading from Pathauto 5.x-1.x to 5.x-2.x (or 6.x-2.x) then you
will probably need to change your patterns.
For content patterns:
[user] is now [author-name]
[cat] is now [term]
There may be other changes as well. Please review the pattern examples on
Administration > Site Configuration > Pathauto
If you upgraded from Pathauto 5.x-1.x directly without enabling Token
first then you will need to
1) download/install the Token module
2) disable the Pathauto module
3) re-enable the Pathauto module
Upgrade to 6.x:
Note that the settings page has moved so that it is more logically grouped with
other URL alias related items under
Administer > Site building > URL alias > Automated alias settings
$Id: INSTALL.txt,v 1.6 2010/03/15 18:24:56 davereid Exp $
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
Cambridge, MA 02139, 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 Library 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
Please read this file and also the INSTALL.txt.
They contain answers to many common questions.
If you are developing for this module, the API.txt may be interesting.
If you are upgrading, check the CHANGELOG.txt for major changes.
**Description:
The Pathauto module provides support functions for other modules to
automatically generate aliases based on appropriate criteria, with a
central settings path for site administrators.
Implementations are provided for core content types: nodes, taxonomy
terms, and users (including blogs and tracker pages).
Pathauto also provides a way to delete large numbers of aliases. This feature
is available at Administer > Site building > URL aliases > Delete aliases
**Benefits:
Besides making the page address more reflective of its content than
"node/138", it's important to know that modern search engines give
heavy weight to search terms which appear in a page's URL. By
automatically using keywords based directly on the page content in the URL,
relevant search engine hits for your page can be significantly
enhanced.
**Installation AND Upgrades:
See the INSTALL.txt file.
**Notices:
Pathauto just adds URL aliases to content, users, and taxonomy terms.
Because it's an alias, the standard Drupal URL (for example node/123 or
taxonomy/term/1) will still function as normal. If you have external links
to your site pointing to standard Drupal URLs, or hardcoded links in a module,
template, content or menu which point to standard Drupal URLs it will bypass
the alias set by Pathauto.
There are reasons you might not want two URLs for the same content on your
site. If this applies to you, please note that you will need to update any
hard coded links in your content or blocks.
If you use the "system path" (i.e. node/10) for menu items and settings like
that, Drupal will replace it with the url_alias.
For external links, you might want to consider the Path Redirect or
Global Redirect modules, which allow you to set forwarding either per item or
across the site to your aliased URLs.
URLs (not) Getting Replaced With Aliases:
Please bear in mind that only URLs passed through Drupal's l() or url()
functions will be replaced with their aliases during page output. If a module
or your template contains hardcoded links, such as 'href="node/$node->nid"'
those won't get replaced with their corresponding aliases. Use the
Drupal API instead:
* 'href="'. url("node/$node->nid") .'"' or
* l("Your link title", "node/$node->nid")
See http://api.drupal.org/api/HEAD/function/url and
http://api.drupal.org/api/HEAD/function/l for more information.
** Disabling Pathauto for a specific content type (or taxonomy)
When the pattern for a content type is left blank, the default pattern will be
used. But if the default pattern is also blank, Pathauto will be disabled
for that content type.
** Bulk Updates Must be Run Multiple Times:
As of 5.x-2.x Pathauto now performs bulk updates in a manner which is more
likely to succeed on large sites. The drawback is that it needs to be run
multiple times. If you want to reduce the number of times that you need to
run Pathauto you can increase the "Maximum number of objects to alias in a
bulk update:" setting under General Settings.
**WYSIWYG Conflicts - FCKEditor, TinyMCE, etc.
If you use a WYSIWYG editor, please disable it for the Pathauto admin page.
Failure to do so may cause errors about "preg_replace" problems due to the <p>
tag being added to the "strings to replace". See http://drupal.org/node/175772
**Credits:
The original module combined the functionality of Mike Ryan's autopath with
Tommy Sundstrom's path_automatic.
Significant enhancements were contributed by jdmquin @ www.bcdems.net.
Matt England added the tracker support.
Other suggestions and patches contributed by the Drupal community.
Current maintainers:
Greg Knaddison - http://growingventuresolutions.com
Mike Ryan - http://mikeryan.name
Frederik 'Freso' S. Olesen - http://freso.dk
**Changes:
See the CHANGELOG.txt file.
$Id: README.txt,v 1.17 2011/01/13 03:27:24 davereid Exp $
<?php
// $Id: pathauto.admin.inc,v 1.46 2011/01/11 19:55:39 davereid Exp $
/**
* @file
* Admin page callbacks for the Pathauto module.
*
* @ingroup pathauto
*/
/**
* Form builder; Configure the URL alias patterns.
*
* @ingroup forms
* @see system_settings_form()
*/
function pathauto_patterns_form($form, $form_state) {
// Call the hook on all modules - an array of 'settings' objects is returned
$all_settings = module_invoke_all('pathauto', 'settings');
foreach ($all_settings as $settings) {
$module = $settings->module;
$patterndescr = $settings->patterndescr;
$patterndefault = $settings->patterndefault;
$groupheader = $settings->groupheader;
$form[$module] = array(
'#type' => 'fieldset',
'#title' => $groupheader,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// Prompt for the default pattern for this module
$variable = 'pathauto_' . $module . '_pattern';
$form[$module][$variable] = array(
'#type' => 'textfield',
'#title' => $patterndescr,
'#default_value' => variable_get($variable, $patterndefault),
'#size' => 65,
'#maxlength' => 1280,
'#element_validate' => array('token_element_validate'),
'#after_build' => array('token_element_validate'),
'#token_types' => array($settings->token_type),
'#min_tokens' => 1,
'#parents' => array($variable),
);
// If the module supports a set of specialized patterns, set
// them up here
if (isset($settings->patternitems)) {
foreach ($settings->patternitems as $itemname => $itemlabel) {
$variable = 'pathauto_' . $module . '_' . $itemname . '_pattern';
$form[$module][$variable] = array(
'#type' => 'textfield',
'#title' => $itemlabel,
'#default_value' => variable_get($variable, ''),
'#size' => 65,
'#maxlength' => 1280,
'#element_validate' => array('token_element_validate'),
'#after_build' => array('token_element_validate'),
'#token_types' => array($settings->token_type),
'#min_tokens' => 1,
'#parents' => array($variable),
);
}
}
// Display the user documentation of placeholders supported by
// this module, as a description on the last pattern
$form[$module]['token_help'] = array(
'#title' => t('Replacement patterns'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form[$module]['token_help']['help'] = array(
'#theme' => 'token_tree',
'#token_types' => array($settings->token_type),
);
}
return system_settings_form($form);
}
/**
* Form builder; Configure the Pathauto settings.
*
* @ingroup forms
* @see system_settings_form()
*/
function pathauto_settings_form($form) {
module_load_include('inc', 'pathauto');
$form['pathauto_verbose'] = array(
'#type' => 'checkbox',
'#title' => t('Verbose'),
'#default_value' => variable_get('pathauto_verbose', FALSE),
'#description' => t('Display alias changes (except during bulk updates).'),
);
$form['pathauto_separator'] = array(
'#type' => 'textfield',
'#title' => t('Separator'),
'#size' => 1,
'#maxlength' => 1,
'#default_value' => variable_get('pathauto_separator', '-'),
'#description' => t('Character used to separate words in titles. This will replace any spaces and punctuation characters. Using a space or + character can cause unexpected results.'),
);
$form['pathauto_case'] = array(
'#type' => 'radios',
'#title' => t('Character case'),
'#default_value' => variable_get('pathauto_case', PATHAUTO_CASE_LOWER),
'#options' => array(
PATHAUTO_CASE_LEAVE_ASIS => t('Leave case the same as source token values.'),
PATHAUTO_CASE_LOWER => t('Change to lower case'),
),
);
$max_length = _pathauto_get_schema_alias_maxlength();
$form['pathauto_max_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum alias length'),
'#size' => 3,
'#maxlength' => 3,
'#default_value' => variable_get('pathauto_max_length', 100),
'#min_value' => 1,
'#max_value' => $max_length,
'#description' => t('Maximum length of aliases to generate. 100 is the recommended length. @max is the maximum possible length. See <a href="@pathauto-help">Pathauto help</a> for details.', array('@pathauto-help' => url('admin/help/pathauto'), '@max' => $max_length)),
'#element_validate' => array('_pathauto_validate_numeric_element'),
);
$form['pathauto_max_component_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum component length'),
'#size' => 3,
'#maxlength' => 3,
'#default_value' => variable_get('pathauto_max_component_length', 100),
'#min_value' => 1,
'#max_value' => $max_length,
'#description' => t('Maximum text length of any component in the alias (e.g., [title]). 100 is the recommended length. @max is the maximum possible length. See <a href="@pathauto-help">Pathauto help</a> for details.', array('@pathauto-help' => url('admin/help/pathauto'), '@max' => $max_length)),
'#element_validate' => array('_pathauto_validate_numeric_element'),
);
$form['pathauto_update_action'] = array(
'#type' => 'radios',
'#title' => t('Update action'),
'#default_value' => variable_get('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE),
'#options' => array(
PATHAUTO_UPDATE_ACTION_NO_NEW => t('Do nothing. Leave the old alias intact.'),
PATHAUTO_UPDATE_ACTION_LEAVE => t('Create a new alias. Leave the existing alias functioning.'),
PATHAUTO_UPDATE_ACTION_DELETE => t('Create a new alias. Delete the old alias.'),
PATHAUTO_UPDATE_ACTION_REDIRECT => t('Create a new alias. Redirect from old alias.'),
),
'#description' => t('What should Pathauto do when updating an existing content item which already has an alias?'),
);
if (!module_exists('path_redirect')) {
// Remove the redirection option if Path redirect is not enabled.
unset($form['pathauto_update_action']['#options'][PATHAUTO_UPDATE_ACTION_REDIRECT]);
if (variable_get('pathauto_update_action', NULL) == PATHAUTO_UPDATE_ACTION_REDIRECT) {
// Fix the current update action variable as well.
variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE);
}
}
$form['pathauto_transliterate'] = array(
'#type' => 'checkbox',
'#title' => t('Transliterate prior to creating alias'),
'#default_value' => variable_get('pathauto_transliterate', FALSE),
'#description' => t('When a pattern includes certain characters (such as those with accents) should Pathauto attempt to transliterate them into the ASCII-96 alphabet? Transliteration is handled by the Transliteration module.'),
);
if (!module_exists('transliteration')) {
// Remove the redirection option if Transliteration is not enabled.
$form['pathauto_transliterate']['#access'] = FALSE;
variable_set('pathauto_transliterate', FALSE);
}
$form['pathauto_reduce_ascii'] = array(
'#type' => 'checkbox',
'#title' => t('Reduce strings to letters and numbers'),
'#default_value' => variable_get('pathauto_reduce_ascii', FALSE),
'#description' => t('Filters the new alias to only letters and numbers found in the ASCII-96 set.'),
);
$form['pathauto_ignore_words'] = array(
'#type' => 'textarea',
'#title' => t('Strings to Remove'),
'#default_value' => variable_get('pathauto_ignore_words', PATHAUTO_IGNORE_WORDS),
'#description' => t('Words to strip out of the URL alias, separated by commas. Do not use this to remove punctuation.'),
'#wysiwyg' => FALSE,
);
$form['punctuation'] = array(
'#type' => 'fieldset',
'#title' => t('Punctuation'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$punctuation = pathauto_punctuation_chars();
foreach ($punctuation as $name => $details) {
$details['default'] = PATHAUTO_PUNCTUATION_REMOVE;
if ($details['value'] == variable_get('pathauto_separator', '-')) {
$details['default'] = PATHAUTO_PUNCTUATION_REPLACE;
}
$form['punctuation']['pathauto_punctuation_' . $name] = array(
'#type' => 'select',
'#title' => $details['name'],
'#default_value' => variable_get('pathauto_punctuation_' . $name, $details['default']),
'#options' => array(
PATHAUTO_PUNCTUATION_REMOVE => t('Remove'),
PATHAUTO_PUNCTUATION_REPLACE => t('Replace by separator'),
PATHAUTO_PUNCTUATION_DO_NOTHING => t('No action (do not replace)'),
),
);
}
return system_settings_form($form);
}
/**
* Validate a form element that should have an numeric value.
*/
function _pathauto_validate_numeric_element($element, &$form_state) {
$value = $element['#value'];
if (!is_numeric($value)) {
form_error($element, t('The field %name is not a valid number.', array('%name' => $element['#title'])));
}
elseif (isset($element['#max_value']) && $value > $element['#max_value']) {
form_error($element, t('The field %name cannot be greater than @max.', array('%name' => $element['#title'], '@max' => $element['#max_value'])));
}
elseif (isset($element['#min_value']) && $value < $element['#min_value']) {
form_error($element, t('The field %name cannot be less than @min.', array('%name' => $element['#title'], '@min' => $element['#min_value'])));
}
}
/**
* Validate pathauto_settings_form form submissions.
*/
function pathauto_settings_form_validate($form, &$form_state) {
module_load_include('inc', 'pathauto');
// Perform a basic check for HTML characters in the strings to remove field.
if (strip_tags($form_state['values']['pathauto_ignore_words']) != $form_state['values']['pathauto_ignore_words']) {
form_set_error('pathauto_ignore_words', t('The <em>Strings to remove</em> field must not contain HTML. Make sure to disable any WYSIWYG editors for this field.'));
}
// Validate that the separator is not set to be removed per http://drupal.org/node/184119
// This isn't really all that bad so warn, but still allow them to save the value.
$separator = $form_state['values']['pathauto_separator'];
$punctuation = pathauto_punctuation_chars();
foreach ($punctuation as $name => $details) {
if ($details['value'] == $separator) {
$action = $form_state['values']['pathauto_punctuation_' . $name];
if ($action == PATHAUTO_PUNCTUATION_REMOVE) {
drupal_set_message(t('You have configured the @name to be the separator and to be removed when encountered in strings. This can cause problems with your patterns and especially with the term:path token. You should probably set the action for @name to be "replace by separator".', array('@name' => $details['name'])), 'error');
}
}
}
}
/**
* Form contructor for path alias bulk update form.
*
* @see pathauto_bulk_update_form_submit()
* @ingroup forms
*/
function pathauto_bulk_update_form() {
$form['#update_callbacks'] = array();
$form['update'] = array(
'#type' => 'checkboxes',
'#title' => t('Select the types of un-aliased paths for which to generate URL aliases'),
'#options' => array(),
'#default_value' => array(),
);
$pathauto_settings = module_invoke_all('pathauto', 'settings');
foreach ($pathauto_settings as $settings) {
if (!empty($settings->batch_update_callback)) {
$form['#update_callbacks'][$settings->batch_update_callback] = $settings;
$form['update']['#options'][$settings->batch_update_callback] = $settings->groupheader;
}
}
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
return $form;
}
/**
* Form submit handler for path alias bulk update form.
*
* @see pathauto_batch_update_form()
* @see pathauto_bulk_update_batch_finished()
*/
function pathauto_bulk_update_form_submit($form, &$form_state) {
$batch = array(
'title' => t('Bulk updating URL aliases'),
'operations' => array(
array('pathauto_bulk_update_batch_start', array()),
),
'finished' => 'pathauto_bulk_update_batch_finished',
'file' => drupal_get_path('module', 'pathauto') . '/pathauto.admin.inc',
);
foreach ($form_state['values']['update'] as $callback) {
if (!empty($callback)) {
$settings = $form['#update_callbacks'][$callback];
if (!empty($settings->batch_file)) {
$batch['operations'][] = array('pathauto_bulk_update_batch_process', array($callback, $settings));
}
else {
$batch['operations'][] = array($callback, array());
}
}
}
batch_set($batch);
}
/**
* Batch callback; count the current number of URL aliases for comparison later.
*/
function pathauto_bulk_update_batch_start(&$context) {
$context['results']['count_before'] = db_select('url_alias')->countQuery()->execute()->fetchField();
}
/**
* Common batch processing callback for all operations.
*
* Required to load our include the proper batch file.
*/
function pathauto_bulk_update_batch_process($callback, $settings, &$context) {
if (!empty($settings->batch_file)) {
require_once DRUPAL_ROOT . '/' . $settings->batch_file;
}
return $callback($context);
}
/**
* Batch finished callback.
*/
function pathauto_bulk_update_batch_finished($success, $results, $operations) {
if ($success) {
// Count the current number of URL aliases after the batch is completed
// and compare to the count before the batch started.
$results['count_after'] = db_select('url_alias')->countQuery()->execute()->fetchField();
$results['count_changed'] = max($results['count_after'] - $results['count_before'], 0);
if ($results['count_changed']) {
drupal_set_message(format_plural($results['count_changed'], 'Generated 1 URL alias.', 'Generated @count URL aliases.'));
}
else {
drupal_set_message('No new URL aliases to generate.');
}
}
else {
$error_operation = reset($operations);
drupal_set_message(t('An error occurred while processing @operation with arguments : @args', array('@operation' => $error_operation[0], '@args' => print_r($error_operation[0], TRUE))));
}
}
/**
* Menu callback; select certain alias types to delete.
*/
function pathauto_admin_delete() {
/* TODO:
1) all - DONE
2) all node aliases - DONE
4) all user aliases - DONE
5) all taxonomy aliases - DONE
6) by node type
7) by taxonomy vocabulary
8) no longer existing aliases (see http://drupal.org/node/128366 )
9) where src like 'pattern' - DON'T DO
10) where dst like 'pattern' - DON'T DO
*/
$form['delete'] = array(
'#type' => 'fieldset',
'#title' => t('Choose aliases to delete'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
// First we do the "all" case
$total_count = db_query('SELECT count(1) FROM {url_alias}')->fetchField();
$form['delete']['all_aliases'] = array(
'#type' => 'checkbox',
'#title' => t('All aliases'),
'#default_value' => FALSE,
'#description' => t('Delete all aliases. Number of aliases which will be deleted: %count.', array('%count' => $total_count)),
);
// Next, iterate over an array of objects/alias types which can be deleted and provide checkboxes
$objects = module_invoke_all('path_alias_types');
foreach ($objects as $internal_name => $label) {
$count = db_query("SELECT count(1) FROM {url_alias} WHERE source LIKE :src", array(':src' => "$internal_name%"))->fetchField();
$form['delete'][$internal_name] = array(
'#type' => 'checkbox',
'#title' => $label, // This label is sent through t() in the hard coded function where it is defined
'#default_value' => FALSE,
'#description' => t('Delete aliases for all @label. Number of aliases which will be deleted: %count.', array('@label' => $label, '%count' => $count)),
);
}
// Warn them and give a button that shows we mean business
$form['warning'] = array('#value' => '<p>' . t('<strong>Note:</strong> there is no confirmation. Be sure of your action before clicking the "Delete aliases now!" button.<br />You may want to make a backup of the database and/or the url_alias table prior to using this feature.') . '</p>');
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Delete aliases now!'),
);
return $form;
}
/**
* Process pathauto_admin_delete form submissions.
*/
function pathauto_admin_delete_submit($form, &$form_state) {
foreach ($form_state['values'] as $key => $value) {
if ($value) {
if ($key === 'all_aliases') {
db_delete('url_alias')
->execute();
drupal_set_message(t('All of your path aliases have been deleted.'));
}
$objects = module_invoke_all('path_alias_types');
if (array_key_exists($key, $objects)) {
db_delete('url_alias')
->condition('source', db_like($key) . '%', 'LIKE')
->execute();
drupal_set_message(t('All of your %type path aliases have been deleted.', array('%type' => $objects[$key])));
}
}
}
$form_state['redirect'] = 'admin/config/search/path/delete_bulk';
}
<?php
// $Id: pathauto.api.php,v 1.2 2010/08/08 23:46:36 davereid Exp $
/**
* @file
* Documentation for pathauto API.
*
* @see hook_token_info
* @see hook_tokens
*/
function hook_path_alias_types() {
}
function hook_pathauto($op) {
}
function hook_pathauto_alias_alter(&$alias, array $context) {
}
This diff is collapsed.
; $Id: pathauto.info,v 1.13 2010/08/11 17:30:01 davereid Exp $
name = Pathauto
description = Provides a mechanism for modules to automatically generate aliases for the content they manage.
dependencies[] = path
dependencies[] = token
core = 7.x
files[] = pathauto.admin.inc
files[] = pathauto.inc
files[] = pathauto.module
files[] = pathauto.install
files[] = pathauto.test
files[] = pathauto.pathauto.inc
configure = admin/config/search/path/patterns
recommends[] = path_redirect
; Information added by drupal.org packaging script on 2011-01-13
version = "7.x-1.0-beta1"
core = "7.x"
project = "pathauto"
datestamp = "1294891601"
<?php
// $Id: pathauto.install,v 1.30 2011/01/11 19:55:39 davereid Exp $
/**
* @file
* Install, update, and uninstall functions for Pathauto.
*
* @ingroup pathauto
*/
/**
* Implements hook_install().
*/
function pathauto_install() {
// Set some default variables necessary for the module to perform.
variable_set('pathauto_node_pattern', 'content/[node:title]');
variable_set('pathauto_taxonomy_term_pattern', '[term:vocabulary]/[term:name]');
variable_set('pathauto_forum_pattern', '[term:vocabulary]/[term:name]');
variable_set('pathauto_user_pattern', 'users/[user:name]');
variable_set('pathauto_blog_pattern', 'blogs/[user:name]');
// Set the default separator character to replace instead of remove (default).
variable_set('pathauto_punctuation_hyphen', 1);
// Set the weight to 1
db_update('system')
->fields(array('weight' => 1))
->condition('type', 'module')
->condition('name', 'pathauto')
->execute();
}
/**
* Implements hook_uninstall().
*/
function pathauto_uninstall() {
// Delete all the pathauto variables and then clear the variable cache
db_query("DELETE FROM {variable} WHERE name LIKE 'pathauto_%'");
cache_clear_all('variables', 'cache');
}
/**
* Remove the unsupported user/%/contact and user/%/tracker pattern variables.
*/
function pathauto_update_6200() {
variable_del('pathauto_contact_bulkupdate');
variable_del('pathauto_contact_pattern');
variable_del('pathauto_contact_supportsfeeds');
variable_del('pathauto_contact_applytofeeds');
variable_del('pathauto_tracker_bulkupdate');
variable_del('pathauto_tracker_pattern');
variable_del('pathauto_tracker_supportsfeeds');
variable_del('pathauto_tracker_applytofeeds');
}
/**
* Empty update since it is handled by pathauto_update_7000().
*/
function pathauto_update_6201() {
}
/**
* Remove obsolete variables since batch API is now used.
*/
function pathauto_update_7000() {
variable_del('pathauto_max_bulk_update');
variable_del('pathauto_node_bulkupdate');
variable_del('pathauto_taxonomy_bulkupdate');
variable_del('pathauto_forum_bulkupdate');
variable_del('pathauto_user_bulkupdate');
variable_del('pathauto_blog_bulkupdate');
variable_del('pathauto_modulelist');
variable_del('pathauto_indexaliases');
variable_del('pathauto_indexaliases_bulkupdate');
}
/**
* Taxonomy and forum feed suffixes changed from '0\/feed' to 'feed'.
*/
function pathauto_update_7001() {
if (variable_get('pathauto_taxonomy_applytofeeds', '') == '0/feed') {
variable_set('pathauto_taxonomy_applytofeeds', 'feed');
}
if (variable_get('pathauto_forum_applytofeeds', '') == '0/feed') {
variable_set('pathauto_forum_applytofeeds', 'feed');
}
}
/**
* Update pathauto_taxonomy_[vid]_pattern variables to pathauto_taxonomy_[machinename]_pattern.
*/
function pathauto_update_7002() {
if (module_exists('taxonomy')) {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vid => $vocabulary) {
if ($vid == variable_get('forum_nav_vocabulary', '')) {
// Skip the forum vocabulary.
continue;
}
if ($pattern = variable_get('pathauto_taxonomy_' . $vid . '_pattern', '')) {
variable_set('pathauto_taxonomy_' . $vocabulary->machine_name . '_pattern', $pattern);
}
variable_del('pathauto_taxonomy_' . $vid . '_pattern');
}
}
}
/**
* Rename 'taxonomy' variables to use the entity type 'taxonomy_term'.
*/
function pathauto_update_7003() {
$variables = db_query("SELECT name FROM {variable} WHERE name LIKE :pattern AND name NOT LIKE :pattern2", array(':pattern' => db_like("pathauto_taxonomy_") . '%', ':pattern2' => db_like("pathauto_taxonomy_term_") . '%'))->fetchCol();
foreach ($variables as $variable) {
$value = variable_get($variable);
variable_del($variable);
$variable = strtr($variable, array('pathauto_taxonomy_' => 'pathauto_taxonomy_term_'));
variable_set($variable, $value);
}
}
/**
* Remove obsolete variables for removed feed handling.
*/
function pathauto_update_7004() {
variable_del('pathauto_node_supportsfeeds');
variable_del('pathauto_node_applytofeeds');
variable_del('pathauto_taxonomy_supportsfeeds');
variable_del('pathauto_taxonomy_applytofeeds');
variable_del('pathauto_forum_supportsfeeds');
variable_del('pathauto_forum_applytofeeds');
variable_del('pathauto_user_supportsfeeds');
variable_del('pathauto_user_applytofeeds');
variable_del('pathauto_blog_supportsfeeds');
variable_del('pathauto_blog_applytofeeds');
}
/**
* Build a list of Drupal 6 tokens and their Drupal 7 token names.
*/
function _pathauto_upgrade_token_list() {
$tokens = array(
//'catpath' => 'node:term-lowest:parent:path][node:term-lowest',
//'catalias' => 'node:term-lowest:path',
'termpath' => 'term:parent:path][term:name',
'termalias' => 'term:path',
'bookpathalias' => 'node:book:parent:path',
);
}
// $Id: pathauto.js,v 1.9 2010/11/11 17:34:54 davereid Exp $
(function ($) {
Drupal.behaviors.pathFieldsetSummaries = {
attach: function (context) {
$('fieldset.path-form', context).drupalSetSummary(function (context) {
var path = $('.form-item-path-alias input').val();
var automatic = $('.form-item-path-pathauto input').attr('checked');
if (automatic) {
return Drupal.t('Automatic alias');
}
if (path) {
return Drupal.t('Alias: @alias', { '@alias': path });
}
else {
return Drupal.t('No alias');
}
});
}
};
})(jQuery);
This diff is collapsed.
<?php
// $Id: pathauto.pathauto.inc,v 1.7 2011/01/13 03:27:23 davereid Exp $
/**
* @file
* Pathauto integration for core modules.
*
* @ingroup pathauto
*/
/**
* Implements hook_path_alias_types().
*
* Used primarily by the bulk delete form.
*/
function pathauto_path_alias_types() {
$objects['user/'] = t('Users');
$objects['node/'] = t('Content');
if (module_exists('blog')) {
$objects['blog/'] = t('User blogs');
}
if (module_exists('taxonomy')) {
$objects['taxonomy/term/'] = t('Taxonomy terms');
}
if (module_exists('forum')) {
$objects['forum/'] = t('Forums');
}
return $objects;
}
/**
* Implements hook_pathauto().
*
* This function is empty so that the other core module implementations can be
* defined in this file. This is because in pathauto_module_implements_alter()
* we add pathauto to be included first. The module system then peforms a
* check on any subsequent run if this function still exists. If this does not
* exist, than this file will not get included and the core implementations
* will never get run.
*
* @see pathauto_module_implements_alter().
*/
function pathauto_pathauto() {
// Empty hook; see the above comment.
}
/**
* Implements hook_pathauto().
*/
function node_pathauto($op) {
switch ($op) {
case 'settings':
$settings = array();
$settings['module'] = 'node';
$settings['token_type'] = 'node';
$settings['groupheader'] = t('Content paths');
$settings['patterndescr'] = t('Default path pattern (applies to all content types with blank patterns below)');
$settings['patterndefault'] = 'content/[node:title]';
$settings['batch_update_callback'] = 'node_pathauto_bulk_update_batch_process';
$settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc';
$languages = array();
if (module_exists('locale')) {
$languages = array(LANGUAGE_NONE => t('language neutral')) + locale_language_list('name');
}
foreach (node_type_get_names() as $node_type => $node_name) {
if (count($languages) && variable_get('language_content_type_' . $node_type, 0)) {
$settings['patternitems'][$node_type] = t('Default path pattern for @node_type (applies to all @node_type content types with blank patterns below)', array('@node_type' => $node_name));
foreach ($languages as $lang_code => $lang_name) {
$settings['patternitems'][$node_type . '_' . $lang_code] = t('Pattern for all @language @node_type paths', array('@node_type' => $node_name, '@language' => $lang_name));
}
}
else {
$settings['patternitems'][$node_type] = t('Pattern for all @node_type paths', array('@node_type' => $node_name));
}
}
return (object) $settings;
default:
break;
}
}
/**
* Batch processing callback; Generate aliases for nodes.
*/
function node_pathauto_bulk_update_batch_process(&$context) {
if (!isset($context['sandbox']['current'])) {
$context['sandbox']['count'] = 0;
$context['sandbox']['current'] = 0;
}
$query = db_select('node', 'n');
$concat = _pathauto_sql_concat("'node/'", 'n.nid');
$query->leftJoin('url_alias', 'ua', "$concat = ua.source");
$query->addField('n', 'nid');
$query->isNull('ua.source');
$query->condition('n.nid', $context['sandbox']['current'], '>');
$query->orderBy('n.nid');
$query->addTag('pathauto_bulk_update');
$query->addMetaData('entity', 'node');
// Get the total amount of items to process.
if (!isset($context['sandbox']['total'])) {
$context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
// If there are no nodes to update, the stop immediately.
if (!$context['sandbox']['total']) {
$context['finished'] = 1;
return;
}
}
$query->range(0, 25);
$nids = $query->execute()->fetchCol();
pathauto_node_update_alias_multiple($nids, 'bulkupdate');
$context['sandbox']['count'] += count($nids);
$context['sandbox']['current'] = max($nids);
$context['message'] = t('Updated alias for node @nid.', array('@nid' => end($nids)));
if ($context['sandbox']['count'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
}
}
/**
* Implements hook_pathauto().
*/
function taxonomy_pathauto($op) {
switch ($op) {
case 'settings':
$settings = array();
$settings['module'] = 'taxonomy_term';
$settings['token_type'] = 'term';
$settings['groupheader'] = t('Taxonomy term paths');
$settings['patterndescr'] = t('Default path pattern (applies to all vocabularies with blank patterns below)');
$settings['patterndefault'] = '[term:vocabulary]/[term:name]';
$settings['batch_update_callback'] = 'taxonomy_pathauto_bulk_update_batch_process';
$settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc';
$vocabularies = taxonomy_get_vocabularies();
if (count($vocabularies)) {
$settings['patternitems'] = array();
foreach ($vocabularies as $vid => $vocabulary) {
if ($vid == variable_get('forum_nav_vocabulary', '')) {
// Skip the forum vocabulary.
continue;
}
$settings['patternitems'][$vocabulary->machine_name] = t('Pattern for all %vocab-name paths', array('%vocab-name' => $vocabulary->name));
}
}
return (object) $settings;
default:
break;
}
}
/**
* Batch processing callback; Generate aliases for taxonomy terms.
*/
function taxonomy_pathauto_bulk_update_batch_process(&$context) {
if (!isset($context['sandbox']['current'])) {
$context['sandbox']['count'] = 0;
$context['sandbox']['current'] = 0;
}
$query = db_select('taxonomy_term_data', 'td');
$concat = _pathauto_sql_concat("'taxonomy/term/'", 'td.tid');
$query->leftJoin('url_alias', 'ua', "$concat = ua.source");
$query->addField('td', 'tid');
$query->isNull('ua.source');
// Exclude the forums terms.
if ($forum_vid = variable_get('forum_nav_vocabulary', '')) {
$query->condition('td.vid', $forum_vid, '<>');
}
$query->orderBy('td.tid');
$query->addTag('pathauto_bulk_update');
$query->addMetaData('entity', 'taxonomy_term');
// Get the total amount of items to process.
if (!isset($context['sandbox']['total'])) {
$context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
// If there are no nodes to update, the stop immediately.
if (!$context['sandbox']['total']) {
$context['finished'] = 1;
return;
}
}
$query->range(0, 25);
$tids = $query->execute()->fetchCol();
pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
$context['sandbox']['count'] += count($tids);
$context['sandbox']['current'] = max($tids);
$context['message'] = t('Updated alias for term @tid.', array('@tid' => end($tids)));
if ($context['sandbox']['count'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
}
}
/**
* Implements hook_pathauto() for forum module.
*/
function forum_pathauto($op) {
switch ($op) {
case 'settings':
$settings = array();
$settings['module'] = 'forum';
$settings['token_type'] = 'term';
$settings['groupheader'] = t('Forum paths');
$settings['patterndescr'] = t('Pattern for forums and forum containers');
$settings['patterndefault'] = '[term:vocabulary]/[term:name]';
$settings['batch_update_callback'] = 'forum_pathauto_bulk_update_batch_process';
$settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc';
return (object) $settings;
default:
break;
}
}
/**
* Batch processing callback; Generate aliases for forums.
*/
function forum_pathauto_bulk_update_batch_process(&$context) {
if (!isset($context['sandbox']['current'])) {
$context['sandbox']['count'] = 0;
$context['sandbox']['current'] = 0;
}
$query = db_select('taxonomy_term_data', 'td');
$concat = _pathauto_sql_concat("'forum/'", 'td.tid');
$query->leftJoin('url_alias', 'ua', "$concat = ua.source");
$query->addField('td', 'tid');
$query->isNull('ua.source');
$query->condition('vid', variable_get('forum_nav_vocabulary', ''));
$query->orderBy('td.tid');
$query->addTag('pathauto_bulk_update');
$query->addMetaData('entity', 'taxonomy_term');
// Get the total amount of items to process.
if (!isset($context['sandbox']['total'])) {
$context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
// If there are no nodes to update, the stop immediately.
if (!$context['sandbox']['total']) {
$context['finished'] = 1;
return;
}
}
$query->range(0, 25);
$tids = $query->execute()->fetchCol();
pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
$context['sandbox']['count'] += count($tids);
$context['sandbox']['current'] = max($tids);
$context['message'] = t('Updated alias for fourm @tid.', array('@tid' => end($tids)));
if ($context['sandbox']['count'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
}
}
/**
* Implements hook_pathauto().
*/
function user_pathauto($op) {
switch ($op) {
case 'settings':
$settings = array();
$settings['module'] = 'user';
$settings['token_type'] = 'user';
$settings['groupheader'] = t('User paths');
$settings['patterndescr'] = t('Pattern for user account page paths');
$settings['patterndefault'] = 'users/[user:name]';
$settings['batch_update_callback'] = 'user_pathauto_bulk_update_batch_process';
$settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc';
return (object) $settings;
default:
break;
}
}
/**
* Batch processing callback; Generate aliases for users.
*/
function user_pathauto_bulk_update_batch_process(&$context) {
if (!isset($context['sandbox']['current'])) {
$context['sandbox']['count'] = 0;
$context['sandbox']['current'] = 0;
}
$query = db_select('users', 'u');
$concat = _pathauto_sql_concat("'user/'", 'u.uid');
$query->leftJoin('url_alias', 'ua', "$concat = ua.source");
$query->addField('u', 'uid');
$query->isNull('ua.source');
$query->condition('u.uid', $context['sandbox']['current'], '>');
$query->orderBy('u.uid');
$query->addTag('pathauto_bulk_update');
$query->addMetaData('entity', 'user');
// Get the total amount of items to process.
if (!isset($context['sandbox']['total'])) {
$context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
// If there are no nodes to update, the stop immediately.
if (!$context['sandbox']['total']) {
$context['finished'] = 1;
return;
}
}
$query->range(0, 25);
$uids = $query->execute()->fetchCol();
pathauto_user_update_alias_multiple($uids, 'bulkupdate', array('alias blog' => FALSE));
$context['sandbox']['count'] += count($uids);
$context['sandbox']['current'] = max($uids);
$context['message'] = t('Updated alias for user @uid.', array('@uid' => end($uids)));
if ($context['sandbox']['count'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
}
}
/**
* Implements hook_pathauto().
*/
function blog_pathauto($op) {
switch ($op) {
case 'settings':
$settings = array();
$settings['module'] = 'blog';
$settings['token_type'] = 'user';
$settings['groupheader'] = t('Blog paths');
$settings['patterndescr'] = t('Pattern for blog page paths');
$settings['patterndefault'] = 'blogs/[user:name]';
$settings['batch_update_callback'] = 'blog_pathauto_bulk_update_batch_process';
$settings['batch_file'] = drupal_get_path('module', 'pathauto') . '/pathauto.pathauto.inc';
return (object) $settings;
default:
break;
}
}
/**
* Batch processing callback; Generate aliases for blogs.
*/
function blog_pathauto_bulk_update_batch_process(&$context) {
if (!isset($context['sandbox']['current'])) {
$context['sandbox']['count'] = 0;
$context['sandbox']['current'] = 0;
}
$query = db_select('users', 'u');
$concat = _pathauto_sql_concat("'blog/'", 'u.uid');
$query->leftJoin('url_alias', 'ua', "$concat = ua.source");
$query->addField('u', 'uid');
$query->isNull('ua.source');
$query->condition('u.uid', $context['sandbox']['current'], '>');
$query->orderBy('u.uid');
$query->addTag('pathauto_bulk_update');
$query->addMetaData('entity', 'user');
// Get the total amount of items to process.
if (!isset($context['sandbox']['total'])) {
$context['sandbox']['total'] = $query->countQuery()->execute()->fetchField();
// If there are no nodes to update, the stop immediately.
if (!$context['sandbox']['total']) {
$context['finished'] = 1;
return;
}
}
$query->range(0, 25);
$uids = $query->execute()->fetchCol();
$accounts = user_load_multiple($uids);
foreach ($accounts as $account) {
pathauto_blog_update_alias($account, 'bulkupdate');
}
$context['sandbox']['count'] += count($uids);
$context['sandbox']['current'] = max($uids);
$context['message'] = t('Updated alias for blog user @uid.', array('@uid' => end($uids)));
if ($context['sandbox']['count'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
$Id: README.txt,v 1.2 2010/03/06 22:12:11 davereid Exp $
Provides common and resuable token UI elements and missing core tokens.
sites/all/modules/token/arrow-down.png

118 B

sites/all/modules/token/arrow-right.png

127 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment