Issue #1016038 by arrrgh: Avoid "Undefined Index" error.
[project/nitobe.git] / theme-settings.php
1 <?php
2 /**
3 * @file
4 * Provides the settings for the Nitobe theme.
5 */
6
7 require_once drupal_get_path("theme", "nitobe") . "/nitobe.utils.inc";
8
9 /**
10 * Exposes Nitobe's theme settings.
11 *
12 * @param array &$form
13 * Nested array of form elements that comprise the form.
14 * @param array &$form_state
15 * A keyed array containing the current state of the form. The arguments that
16 * drupal_get_form() was originally called with are available in the array
17 * $form_state['build_info']['args'].
18 */
19 function nitobe_form_system_theme_settings_alter(&$form, &$form_state) {
20 $form["nitobe_general_settings"] = array(
21 "#type" => "fieldset",
22 "#title" => "General Nitobe settings",
23 );
24
25 // -- What ordering should be used for the content and sidebars?
26 $default = theme_get_setting("nitobe_content_placement", "nitobe");
27 $desc = t("Where should the sidebars be placed?");
28 $options = array(
29 "center" => "On either side of the content region.",
30 "right" => "Right of the content region.",
31 "left" => "Left of the content region.",
32 );
33
34 $form["nitobe_general_settings"]['nitobe_content_placement'] = array(
35 "#type" => "select",
36 "#title" => t("Sidebar placement"),
37 "#options" => $options,
38 "#default_value" => $default,
39 "#description" => $desc,
40 );
41
42 // -- How many page items to put in the pager widgets.
43 $default = theme_get_setting("nitobe_pager_page_count", "nitobe");
44 $options = range(3, 10);
45 $desc = t("The number of default pages to include in pager controls. If you are using a three column layout, a lower number here will work better.");
46
47 $form["nitobe_general_settings"]['nitobe_pager_page_count'] = array(
48 "#type" => 'select',
49 "#title" => t('Pager item count'),
50 "#options" => drupal_map_assoc($options),
51 "#default_value" => $default,
52 "#description" => $desc,
53 );
54
55 _nitobe_add_header_settings($form);
56 _nitobe_add_time_format_settings($form);
57 }
58
59
60 /**
61 * Adds the date/time format settings to the settings form.
62 *
63 * @param array &$form
64 * Nested array of form elements that comprise the form.
65 */
66 function _nitobe_add_time_format_settings(&$form) {
67 $options = array(
68 "attributes" => array("target" => "_blank"),
69 "absolute" => TRUE,
70 "external" => TRUE,
71 );
72
73 $subs = array(
74 "!link" => l(t("date()"), "http://php.net/manual/en/function.date.php",
75 $options),
76 );
77
78 $desc = t("These settings are used to control how dates are rendered on nodes and comments. Refer to the documentation for PHP's !link function for details on date formats.",
79 $subs);
80 $form["nitobe_datetime_settings"] = array(
81 "#type" => "fieldset",
82 "#title" => "Date and time formats",
83 "#description" => $desc,
84 );
85
86 // -- The node timestamp format
87 $default = theme_get_setting("nitobe_node_datestamp_format", "nitobe");
88 $desc = t("This controls how dates are rendered in a node's header.");
89 $form["nitobe_datetime_settings"]["nitobe_node_datestamp_format"] = array(
90 "#type" => "textfield",
91 "#title" => t("Node date format"),
92 "#size" => 32,
93 "#max_length" => 64,
94 "#description" => $desc,
95 "#default_value" => $default,
96 );
97
98 // -- The comment attribution date format
99 $default = theme_get_setting("nitobe_comment_date_format", "nitobe");
100 $desc = t("This controls how a comment's date is rendered in the author attribution text.");
101 $form["nitobe_datetime_settings"]["nitobe_comment_date_format"] = array(
102 "#type" => "textfield",
103 "#title" => t("Comment date format"),
104 "#size" => 32,
105 "#max_length" => 64,
106 "#description" => $desc,
107 "#default_value" => $default,
108 );
109
110 // -- The comment attribution time format
111 $default = theme_get_setting("nitobe_comment_time_format", "nitobe");
112 $desc = t("This controls how a comment's time is rendered in the author attribution text.");
113 $form["nitobe_datetime_settings"]["nitobe_comment_time_format"] = array(
114 "#type" => "textfield",
115 "#title" => t("Comment date format"),
116 "#size" => 32,
117 "#max_length" => 64,
118 "#description" => $desc,
119 "#default_value" => $default,
120 );
121 }
122
123
124 /**
125 * Adds the header settings to the settings form.
126 *
127 * @param array $form
128 * The form element array to add the settings fields to.
129 */
130 function _nitobe_add_header_settings(&$form) {
131 $form["nitobe_header_settings"] = array(
132 "#type" => "fieldset",
133 "#title" => "Page header settings",
134 );
135
136 // -- Should the alternating color title effect be applied?
137 $default = theme_get_setting("nitobe_title_effect", "nitobe");
138 $desc = t("Should the title be adjusted to apply an alternate color to every other word and remove inter-word spacing?");
139 $form["nitobe_header_settings"]["nitobe_title_effect"] = array(
140 "#type" => "checkbox",
141 "#title" => t("Apply title effect"),
142 "#default_value" => $default,
143 "#description" => $desc,
144 );
145
146 // -- Get the header image list.
147 $images = _nitobe_get_header_list(TRUE);
148 $options = array("<random>" => "<Random Header Image>");
149
150 foreach ($images as $filename => $data) {
151 $options[$filename] = $data->pretty_name;
152 }
153
154 // -- The setting for the header image.
155 $current = theme_get_setting("nitobe_header_image", "nitobe");
156 $default = in_array($current, array_keys($options)) ? $current : "<random>";
157 $form["nitobe_header_settings"]["nitobe_header_image"] = array(
158 "#type" => "select",
159 "#title" => t("Header image"),
160 "#options" => $options,
161 "#default_value" => $default,
162 );
163
164 // -- Show the header image if the mastead region has content?
165 $default = theme_get_setting("nitobe_masthead_always_show", "nitobe");
166 $desc = t("By default, if there is block content in the Masthead region, the header image will not be displayed. Check this box to cause the header image to be displayed as the region's background image.");
167 $form["nitobe_header_settings"]["nitobe_masthead_always_show"] = array(
168 "#type" => "checkbox",
169 "#title" => t("Always show masthead image"),
170 "#default_value" => $default,
171 "#description" => $desc,
172 );
173 }