forked from mkalkbrenner/themekey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
themekey_ui_helper.inc
89 lines (79 loc) · 2.05 KB
/
themekey_ui_helper.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @file
* helper functions for ThemeKey UI feature to add a theme option to the
* 'URL aliases' administration if module "Path" is enabled.
*
* @see themekey_ui.module
* @see themekey_ui_admin.inc
*
* @author Markus Kalkbrenner | Cocomore AG
* @see http://drupal.org/user/124705
*
* @author profix898
* @see http://drupal.org/user/35192
*/
require_once(drupal_get_path('module', 'themekey') .'/themekey_build.inc');
/**
* Returns a theme assigned to a drupal path alias using
* a ThemeKey Theme Switching Rule which is not part of a chain
*
* @param $path
* drupal path as string
*
* @return
* array with to elements:
* - id of the database entry in table themekey_properties
* or '0' if no entry exists
* - the theme
*/
function themekey_ui_get_path_theme($path) {
$serialized_empty_array = serialize(array());
if ($result = db_query("SELECT id, theme FROM {themekey_properties} WHERE property = 'drupal:path' AND operator = '=' AND value = '%s' AND wildcards = '%s' AND parent = 0", $path, $serialized_empty_array)) {
while ($row = db_fetch_array($result)) {
if (!db_result(db_query("SELECT COUNT(*) FROM {themekey_properties} WHERE parent = %d", $row['id']))) {
return array($row['id'], $row['theme']);
}
}
}
return array(0, 'default');
}
/**
* Saves a theme assigned to a path alias as
* ThemeKey rule
*
* @see themekey_rule_set()
*
* @param $path
* drupa path alias as string
*
* @param $theme
* assigned drupal theme as string
*
* @param $id
* the id of an existing rule if this
* one should be modified
*/
function themekey_ui_set_path_theme($path, $theme = 'default', $id = 0) {
$item = array(
'property' => 'drupal:path',
'value' => $path,
'theme' => $theme,
'enabled' => 1,
);
if ($id > 0) {
$item['id'] = $id;
}
themekey_rule_set($item);
}
/**
* Deletes a ThemeKey rule.
*
* @see themekey_rule_del()
*
* @param $id
* the id of an existing rule
*/
function themekey_ui_del_path_theme($id) {
return themekey_rule_del($id);
}