Merge lp:~mongolito404/ubuntu-drupal-theme/688289_download_tradmaked_css into lp:ubuntu-drupal-theme

Proposed by Pierre Buyle on 2011-01-13
Status: Merged
Approved by: Michael Lustfield on 2011-01-13
Approved revision: 76
Merged at revision: 76
Proposed branch: lp:~mongolito404/ubuntu-drupal-theme/688289_download_tradmaked_css
Merge into: lp:ubuntu-drupal-theme
Diff against target: 85 lines (+37/-14) 1 file modified
To merge this branch: bzr merge lp:~mongolito404/ubuntu-drupal-theme/688289_download_tradmaked_css
Reviewer Review Type Date Requested Status
Michael Lustfield (community) 2011-01-13 Approve on 2011-01-13
Review via email: mp+46185@code.launchpad.net
To post a comment you must log in.

This looks to be a solid solution to the bug. Could you please commit this to the main branch for D6 and D7?

review: Approve

Preview Diff

1=== modified file 'template.php'
2--- template.php 2010-12-05 09:58:12 +0000
3+++ template.php 2011-01-13 21:30:02 +0000
4@@ -31,7 +31,7 @@
5 );
6
7 $settings = array();
8- $settings = variable_get($theme_key, NULL);
9+ $settings = variable_get($theme_key, array());
10
11 if (module_exists('node')) {
12 foreach (node_get_types() as $type => $name) {
13@@ -86,7 +86,6 @@
14 * Generate / override exsisting variables
15 */
16 function udtheme_preprocess_page(&$vars) {
17- $pallette = udtheme_pallette();
18
19 $vars['menu'] = udtheme_whichmenu($vars['primary_links']);
20 $vars['logo'] = udtheme_buildlogo($vars);
21@@ -94,9 +93,12 @@
22 $vars['help_text'] = udtheme_help($vars['help']);
23 $vars['min_width'] = variable_get('page_minwidth', '1000px');
24 $vars['pg_width'] = pagewidth();
25- $vars['trademark'] = udtheme_trademark();
26-
27- if ($pallette && !$vars['trademark']) {
28+
29+ if ($trademark = udtheme_trademark()) {
30+ $vars['css'] = drupal_add_css($trademark);
31+ $vars['styles'] = drupal_get_css();
32+ }
33+ elseif ($pallette = udtheme_pallette()) {
34 $vars['css'] = drupal_add_css($pallette);
35 $vars['styles'] = drupal_get_css();
36 }
37@@ -197,20 +199,41 @@
38 }
39
40 /**
41- * Add CSS for trademarked sites.
42- * In Drupal 7.x this wil be moved into udtheme_pallette but can't be done at this point.
43+ * Add CSS for trademarked sites. Trademarked CSS files are download into the
44+ * temporary CSS directory.
45 */
46 function udtheme_trademark() {
47- global $language;
48-
49 if (variable_get('udtheme_trademark', FALSE)) {
50- $css = '<link rel="stylesheet" type="text/css" href="http://edge.launchpad.net/ubuntu-drupal-theme/trademark/6.7.0/+download/trademark.css" />' . PHP_EOL;
51- if ($language->direction == LANGUAGE_RTL) {
52- $css = '<link rel="stylesheet" type="text/css" href="http://edge.launchpad.net/ubuntu-drupal-theme/trademark/6.7.0/+download/trademark-rtl.css" />' . PHP_EOL;
53+ $csspath = file_create_path('css');
54+ foreach (array('trademark-rtl.css', 'trademark.css') as $filename) {
55+ $filepath = $csspath .'/'. $filename;
56+ $download = !file_exists($filepath);
57+ if (!$download) {
58+ $stats = stat($filepath);
59+ $download = $stats['ctime'] < (time() - 86400);
60+ }
61+ if ($download) {
62+ $url = 'http://launchpad.net/ubuntu-drupal-theme/trademark/6.7.0/+download/'. $filename;
63+ $response = drupal_http_request($url);
64+ if ($response->code == 303) {
65+ //Handle 303 because drupal_http_request doesn't
66+ $response = drupal_http_request($response->headers['Location']);
67+ }
68+ if (isset($response->data)) {
69+ file_save_data($response->data, $filepath, FILE_EXISTS_REPLACE);
70+ }
71+ else {
72+ watchdog('udtheme', 'Unabled to download <a href="@url">@filename</a>: @code @status_message', array(
73+ '@url' => $url,
74+ '@filename' => $filename,
75+ '@code' => $response->code,
76+ '@status_message' => $response->status_message
77+ ), WATCHDOG_ERROR, $url);
78+ }
79+ }
80 }
81+ return $filepath;
82 }
83-
84- return $css;
85 }
86
87

Subscribers

People subscribed via source and target branches