Releasing v6.x-1.15-beta1.
[project/nodewords.git] / nodewords.api.php
1 <?php
2 /**
3 * @file.
4 * Nodewords hooks.
5 */
6
7 /**
8 * The hook is used from nodewords.module to know which API is supported by the
9 * the module.
10 *
11 * @return
12 * An array containing the following indexes:
13 *
14 * - version - the API version used by the module; basing on this value
15 * Nodewords will take the necessary steps to assure to keep the module
16 * compatible with Nodewords, The minimum API currently supported by the
17 * module is contained in the constant NODEWORDS_MINIMUM_API_VERSION, and
18 * the current API version is contained in the constant
19 * NODEWORDS_API_VERSION.
20 */
21 function hook_nodewords_api() {
22 return array('version' => '1.14');
23 }
24
25 /**
26 * This hook declares the meta tags implemented by the module.
27 *
28 * @return
29 * A nested array containing the following values:
30 *
31 * - attributes - the tag attributes used when outputting the tag.
32 * - callback - the string used to built the name of the functions called for
33 * any meta tags operations.
34 * - context - the contexts in which the meta tags are allowed (and denied).
35 * - label - the label used as title in the fieldset for the form field
36 * shown in the form to edit the meta tags values.
37 * - multiple - if set to TRUE, splits the tag value on each line break and
38 * outputs each item as a fully separate copy of the tag; best used when the
39 * form uses a textarea instead of a textfield.
40 * - permission - the permission associated with the form fields used to
41 * edit the meta tags values; this permission is used only when the meta tag
42 * edit form fields are shown in a form that is accessible not only from the
43 * administrators users (in example, in the node edit form, or in the user
44 * profile form).
45 * - templates - the templates used when the meta tag is output.
46 * - weight - the weight used to order the meta tags before to output them;
47 * the lighter meta tag will be output first. See API.txt for a list of the
48 * weights of all included meta tags.
49 */
50 function hook_nodewords_tags_info() {
51 $tags = array(
52 'dcterms.title' => array(
53 'callback' => 'nodewords_extra_dc_title',
54 'context' => array(
55 'denied' => array(
56 NODEWORDS_TYPE_DEFAULT,
57 ),
58 ),
59 'label' => t('Dublin Core title'),
60 'permission' => 'edit meta tag Dublin Core TITLE',
61 'templates' => array(
62 'head' => array(
63 'dcterms.title' => NODEWORDS_META,
64 ),
65 ),
66 ),
67 'location' => array(
68 'callback' => 'nodewords_extra_location',
69 'label' => t('Location'),
70 'permission' => 'edit location meta tag',
71 'templates' => array(
72 'geo.position' => NODEWORDS_META,
73 'icbm' => NODEWORDS_META,
74 ),
75 ),
76 );
77
78 return $tags;
79 }
80
81 /**
82 * The hook is used to alter the metatags content.
83 *
84 * @param &$output
85 * The array of meta tags values.
86 * @param $parameters
87 * An array of parameters. The currently defined are:
88 * * type - the type of object for the page to which the meta
89 * tags are associated.
90 * * ids - the array of IDs for the object associated with the page.
91 * * output - where the meta tags are being output; the parameter value can
92 * 'head' or 'update index'.
93 */
94 function hook_nodewords_tags_alter(&$output, $parameters) {
95 if (empty($output['abstract']) && $parameters['type'] == NODEWORDS_TYPE_PAGE) {
96 $output['abstract'] = t('Node content');
97 }
98 }
99
100 /**
101 * The hook is used to alter the string containing the metatags output.
102 *
103 * @param &$output
104 * The string to alter.
105 * @param $parameters
106 * An array of parameters. The currently defined are:
107 * * type - the type of object for the page to which the meta
108 * tags are associated.
109 * * ids - the array of IDs for the object associated with the page.
110 * * output - where the meta tags are being output; the parameter value can
111 * 'head' or 'update index'.
112 */
113 function hook_nodewords_tags_output_alter(&$output, $parameters) {
114 $bool = (
115 variable_get('nodewords_add_dc_schema', FALSE) &&
116 isset($parameters['output']) &&
117 $parameters['output'] == 'head'
118 );
119
120 if ($bool) {
121 $output = (
122 '<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />' . "\n" .
123 $output
124 );
125 }
126 }
127
128 /**
129 * The hook is used from the module to determinate the type of the object
130 * associated with the currently viewed page (node, user, taxonomy term), and
131 * the ID of the object.
132 *
133 * @param &$result
134 * the array used to write the result.
135 * @param $arg
136 * the array as obtained from arg().
137 */
138 function hook_nodewords_type_id(&$result, $arg) {
139 if ($arg[0] == 'user') {
140 // User page paths: user/$uid.
141 if (isset($arg[1]) && is_numeric($arg[1])) {
142 $result['type'] = NODEWORDS_TYPE_USER;
143 $result['id'] = $arg[1];
144 }
145 }
146 }
147
148 /**
149 * @} End of "addtogroup Nodewords hooks" .
150 */