5 * Hooks provided by Pathologic.
16 * Allow modules to alter a URL Pathologic is about to create.
18 * This hook is invoked after Pathologic has torn apart a URL it thinks it can
19 * alter properly and is just about to call the url() function to construct the
20 * new URL. Modules can alter the values that Pathologic is about to send to
21 * url(), or even stop Pathologic from altering a URL entirely.
24 * An array with 'path' and 'options' values, which correspond to the $path
25 * and $options parameters of the url() function. The 'options' array has an
26 * extra parameter labeled 'use_original' which is set to FALSE by default.
27 * This parameter is ignored by url(), but if its value is set to TRUE after
28 * all alter hook invocations, Pathologic will return the original, unaltered
29 * path it found in the content instead of calling url() and generating a new
30 * one. Thus, it provides a way for modules to halt the alteration of paths
31 * which Pathologic has incorrectly decided should be altered.
33 * This array contains the result of running parse_url() on the path that
34 * Pathologic found in content, though Pathologic likely altered some of the
35 * values in this array since. It contains another parameter, 'original',
36 * which contains the original URL Pathologic found in the content, unaltered.
37 * You should not alter this value in any way; to alter how Pathologic
38 * constructs the new URL, alter $url_params instead.
40 * This contains the settings Pathologic is using to decide how to alter the
41 * URL; some settings are from the graphical filter form and alterable by the
42 * user, while others are determined programmatically. If you're looking for
43 * the filter settings which Pathologic is currently using (if you've altered
44 * your own field onto the filter settings form, for example), try looking in
45 * $settings['current_settings'].
49 * @see pathologic_replace()
50 * @see http://drupal.org/node/1762022
52 function hook_pathologic_alter(&$url_params, $parts, $settings) {
53 // If we're linking to the "bananas" subdirectory or something under it, then
54 // have Pathologic pass through the original URL, without altering it.
55 if (preg_match('~^bananas(/.*)?$~', $url_params['path'])) {
56 $url_params['options']['use_original'] = TRUE;
59 // If we're linking to a path like "article/something.html", then prepend
60 // "magazine" to the path, but remove the ".html". The end result will look
61 // like "magazine/article/something".
62 if (preg_match('~^article/(.+)\.html$~', $url_params['path'], $matches)) {
63 $url_params['path'] = 'magazine/article/' . $matches[1];
66 // If the URL doesn't have a "foo" query parameter, then add one.
67 if (!is_array($url_params['options']['query'])) {
68 $url_params['options']['query'] = [];
70 if (empty($url_params['options']['query']['foo'])) {
71 $url_params['options']['query']['foo'] = 'bar';
74 // If it's a path to a local image, make sure it's using our CDN server.
75 if (preg_match('~\.(png|gif|jpe?g)$~', $url_params['path'])) {
76 $url_params['path'] = 'http://cdn.example.com/' . $url_params['path'];
77 $url_params['options']['external'] = TRUE;
82 * @} End of "addtogroup hooks".