/[drupal]/contributions/modules/blogtheme/blog_theme.module
ViewVC logotype

Contents of /contributions/modules/blogtheme/blog_theme.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.29 - (show annotations) (download) (as text)
Wed Jan 7 10:55:16 2009 UTC (10 months, 2 weeks ago) by augustin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.28: +2 -2 lines
File MIME type: text/x-php
bugfix. Do not node_load() if $nid == NULL. See #354048.
1 <?php
2 // $Id: blog_theme.module,v 1.28 2008/09/30 08:59:48 augustin Exp $
3
4 /**
5 * @file
6 * This module gives users the option of always having their blog displayed using their default theme
7 * using the $custom_theme variable
8 *
9 * If you have any ideas/patches or requests, please post them
10 * on the project's issue queue at drupal.org
11 */
12
13 /**
14 * Implementation of hook_help().
15 */
16 function blog_theme_help($section, $arg) {
17 switch ($section) {
18 case '':
19 return '';
20 }
21 }
22
23 /**
24 * Implementation of hook_init().
25 */
26 function blog_theme_init() {
27 global $custom_theme;
28 global $user;
29
30 switch (arg(0)) {
31 case 'user':
32 // If the settings say we should use the sites' default theme on user profile pages, break here.
33 if (variable_get('blog_theme_user_profile', 1) == 2) {
34 break;
35 }
36 // else fallthrough...
37 case 'blog':
38 case 'shoutbook':
39 if (arg(1) !='') {
40 $uid = arg(1);
41 $themes = list_themes();
42 $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
43 $custom_theme = !empty($account->blog_theme) && $themes[$account->blog_theme]->status ? $account->blog_theme : variable_get('theme_default', 'garland');
44 }
45 break;
46 case 'node':
47 $nid = arg(1);
48 $themes = list_themes();
49 if ($nid == 'add') { // /node/add
50 $add_type = arg(2); // /node/add/type
51 $allowed_types = variable_get('blog_theme_node_types', array());
52 if (!empty($allowed_types[$add_type])) {
53 $account = user_load(array('uid' => $user->uid, 'status' => 1));
54 $custom_theme = !empty($account->blog_theme) && $themes[$account->blog_theme]->status ? $account->blog_theme : variable_get('theme_default', 'garland');
55 }
56 break;
57 }
58 elseif (is_numeric($nid) && $node = node_load(array('nid' => $nid))) { // /node/$nid
59 $allowed_types = variable_get('blog_theme_node_types', array());
60 if (!empty($allowed_types[$node->type])) {
61 $uid = $node->uid;
62 $account = user_load(array('uid' => $uid, 'status' => 1));
63 $custom_theme = !empty($account->blog_theme) && $themes[$account->blog_theme]->status ? $account->blog_theme : variable_get('theme_default', 'garland');
64 }
65 }
66 break;
67 case 'comment':
68 $nid = arg(2);
69 $themes = list_themes();
70 $node = node_load(array('nid' => $nid));
71 if ($node->type == 'blog') {
72 $uid = $node->uid;
73 $account = user_load(array('uid' => $uid, 'status' => 1));
74 $custom_theme = !empty($account->blog_theme) && $themes[$account->blog_theme]->status ? $account->blog_theme : variable_get('theme_default', 'garland');
75 }
76 break;
77 case 'image':
78 $uid = arg(2);
79 $themes = list_themes();
80 $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
81 $custom_theme = !empty($account->blog_theme) && $themes[$account->blog_theme]->status ? $account->blog_theme : variable_get('theme_default', 'garland');
82 break;
83 }
84
85 }
86
87 /**
88 * Implementation of hook_menu().
89 *
90 * grabs the theme pref from the currently viewed blog's user object and puts in the $custom_theme variable
91 *
92 */
93 function blog_theme_menu() {
94 $items = array();
95
96 $items['admin/settings/blog_theme'] = array(
97 'title' => 'Blog Theme settings',
98 'description' => 'Set content types, and default user page.',
99 'page callback' => 'drupal_get_form',
100 'page arguments' => array('blog_theme_admin_settings_form'),
101 'type' => MENU_NORMAL_ITEM,
102 'access arguments' => array('access administration pages'),
103 );
104
105 return $items;
106 }
107
108 /**
109 * Implementation of hook_perm().
110 */
111 function blog_theme_perm() {
112 return array('select different blog theme');
113 }
114
115 /**
116 * Implementation of hook_theme().
117 */
118 function blog_theme_theme() {
119 return array(
120 'blog_theme_select_form' => array(
121 'arguments' => array('form' => NULL),
122 ),
123 );
124 }
125
126 /**
127 * Implementation of hook_user().
128 */
129 function blog_theme_user($op, &$edit, &$account, $category = NULL) {
130 if ($op == 'form' && $category == 'account') {
131 if (user_access('select different blog theme')) {
132 foreach (list_themes() as $theme) {
133 if ($theme->status) {
134 $enabled[] = $theme;
135 }
136 }
137
138 if (count($enabled) > 1) {
139 ksort($enabled);
140
141 $form['themes'] = array(
142 '#type' => 'fieldset',
143 '#title' => t('Your blog theme configuration'),
144 '#description' => t('Selecting a different theme will change the look of your own blog for both yourself and other visitors.'),
145 '#collapsible' => TRUE,
146 '#theme' => 'blog_theme_select_form'
147 );
148
149 foreach ($enabled as $info) {
150 // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.
151 $info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;
152
153 $info->screenshot = dirname($info->filename) .'/screenshot.png';
154 $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');
155
156 $form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot);
157 $form['themes'][$info->key]['description'] = array(
158 '#type' => 'item',
159 '#title' => $info->name,
160 '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'garland') ? '<br /> <em>'. t('(site default theme)') .'</em>' : '')
161 );
162 $options[$info->key] = '';
163 }
164
165 $form['themes']['blog_theme'] = array(
166 '#type' => 'radios',
167 '#options' => $options,
168 '#default_value' => !empty($edit['blog_theme']) ? $edit['blog_theme'] : ''
169 );
170 $form['#weight'] = 2.5;
171 $form_to_return['blog_theme_select'] = $form;
172 return $form_to_return;
173 }
174 }
175 }
176 }
177
178
179 function theme_blog_theme_select_form($form) {
180 foreach (element_children($form) as $key) {
181 $row = array();
182 if (isset($form[$key]['description']) && is_array($form[$key]['description'])) {
183 $row[] = drupal_render($form[$key]['screenshot']);
184 $row[] = drupal_render($form[$key]['description']);
185 $row[] = drupal_render($form['blog_theme'][$key]);
186 }
187 $rows[] = $row;
188 }
189
190 $header = array(t('Screenshot'), t('Name'), t('Selected'));
191 $output = theme('table', $header, $rows);
192 return $output;
193 }
194
195 /**
196 * Menu callback: form builder for settings page.
197 */
198 function blog_theme_admin_settings_form() {
199 global $user;
200 $form = array();
201
202 $collapsed = TRUE;
203 $time = time();
204 $time_limit = $time - (60 * 60 * 24 * 30);
205 if (variable_get('blog_theme_supported_' . $user->uid, 0) < $time_limit) {
206 $collapsed = FALSE;
207 variable_set('blog_theme_supported_' . $user->uid, $time);
208 }
209
210 $form['blog_theme_support_maintainers'] = array(
211 '#type' => 'fieldset',
212 '#title' => t('Support'),
213 '#collapsible' => TRUE,
214 '#collapsed' => $collapsed,
215 );
216
217 $form['blog_theme_support_maintainers']['blog_theme_support_text'] = array(
218 '#value' => '<p>'
219 . t("<strong>The module blog_theme is charity-ware</strong>.") .'<br />'
220 . t("Please contribute back by supporting the charity work of the following web sites. ") .'<br />'
221 . t("None of the web sites listed here are for profit, and none of them carry advertising.") .'<br />'
222 . t("They are all <strong>web sites dedicated to creating a better tomorrow for the whole society</strong>.") .'<br />'
223 .'</p>'
224 .'<ul>'
225 .'<li>'. t('<a href="http://activistsolutions.org/">Activist Solutions</a>: harvesting grassroots power.') .'</li>'
226 .'<li>'. t('<a href="http://www.reuniting.info/">Reuniting</a>: healing with sexual relationships.') .'</li>'
227 .'<li>'. t('<a href="http://overshoot.tv/">Overshoot TV</a>: making high quality videos and documentaries promoting environmental and economical sustainability.') .'</li>'
228 .'<li>'. t('<a href="http://minguo.info/">Minguo.info</a>: promotting better voting systems, and an experiment in direct democracy.') .'</li>'
229 .'<li>'. t('<a href="http://www.wechange.org/">We Change</a>: because we live in a world of solutions...') .'</li>'
230 .'</ul>'
231 .'<p>'
232 . t("You can support those web sites in the following ways:") .'<br />'
233 .'</p>'
234 .'<ul>'
235 .'<li>'. t("Blog about them.") .'</li>'
236 .'<li>'. t("Put links in a block in a sidebar.") .'</li>'
237 .'<li>'. t("Put links in any other logical place in your web site, where your visitors will find the information useful.") .'</li>'
238 .'<li>'. t("Register and participate if they match your own interest!") .'</li>'
239 .'<li>'. t("We also appreciate if, on behalf of this maintainer, you help <em>any charity of your choice</em>, or/and make a donation to them.") .'</li>'
240 .'</ul>'
241 .'<p>'
242 . t("Please, let the maintainer know about the options you chose.") .'<br />'
243 .'</p>'
244 .'<p>'
245 . t("Thank you for your support and cooperation.") .'<br />'
246 .'</p>',
247 );
248
249 $form['blog_theme_user_profile'] = array(
250 '#type' => 'select',
251 '#title' => t('Which theme to use on the user profile page?'),
252 '#description' => t('If a user has selected a different theme for his/her blog, what theme shall be used on his/her user account page?'),
253 '#options' => array(1 => t("Use the user's selected theme "), 2 => t("Use the site's default theme")),
254 '#default_value' => variable_get('blog_theme_user_profile', 1),
255 );
256
257 $node_types = node_get_types();
258 $options = array();
259 foreach ($node_types AS $type => $o) {
260 $options[$type] = $o->name;
261 }
262 $form['blog_theme_node_types'] = array(
263 '#type' => 'checkboxes',
264 '#title' => t('Which node types shall the user theme be applied to?'),
265 '#description' => t('You can select several node types (e.g. blog) for which the user theme will be applied.'),
266 '#options' => $options,
267 '#default_value' => variable_get('blog_theme_node_types', array()),
268 );
269
270 $form['blog_theme_support_websites'] = array(
271 '#type' => 'fieldset',
272 '#title' => t("Other charitable web sites..."),
273 '#collapsible' => TRUE,
274 '#collapsed' => TRUE,
275 );
276 $form['blog_theme_support_websites']['blog_theme_support_other'] = array(
277 '#value' => '<p>'
278 . t("If your web site meets <em>all</em> the following criteria, you can ask for it to be listed here.")
279 .'</p>'
280 .'<ul>'
281 .'<li>'. t('It uses blog_theme module.') .'</li>'
282 .'<li>'. t('It is a charity (registered or not) dedicated to creating a better society.') .'</li>'
283 .'<li>'. t('It is not for profit.') .'</li>'
284 .'<li>'. t('It does not carry any advertising (e.g. google ads).') .'</li>'
285 .'</ul>',
286 );
287
288 return system_settings_form($form);
289 }
290

  ViewVC Help
Powered by ViewVC 1.1.2