annotate sites/all/modules/pathologic/pathologic.api.php @ 11:b0ee71395280

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