Fixes some PAReview issues.
[project/rijkshuisstijl.git] / functions / misc.php
1 <?php
2 /**
3 * @file
4 * Contains some miscellaneous functions.
5 */
6
7 /**
8 * Get all defined colours as array.
9 *
10 * @return array
11 * All defined colours for this theme.
12 */
13 function _rijkshuisstijl_defined_colours() {
14 return array(
15 'violet',
16 'pink',
17 'red',
18 'ruby',
19 'purple',
20 'orange',
21 'moss_green',
22 'mint_green',
23 'light_blue',
24 'azure',
25 'green',
26 'yellow',
27 'dark_green',
28 'dark_yellow',
29 'dark_brown',
30 'brown',
31 'intra_app',
32 );
33 }
34
35 /**
36 * Get all defined logos as array.
37 *
38 * @return array
39 * An associative array with all defined logos in the starterskit.
40 */
41 function _rijkshuisstijl_defined_logos() {
42 $starterskit = _rijkshuisstijl_init_starterskit();
43 $path = $starterskit['library path'] . '/logos';
44
45 $filesdir = file_scan_directory($path, '/\.png$/', array('nomask' => '/RO_Footer_Homepage/', 'key' => 'name'));
46
47 $search_replacements = array(
48 'AZ_' => 'Algemene Zaken - ',
49 'BZK_' => 'Binnenlandse Zaken en Koninkrijksrelaties - ',
50 'BuZa_' => 'Buitenlandse Zaken - ',
51 'ELI_' => 'Economische Zaken, Landbouw en Innovatie - ',
52 'D_' => 'Defensie - ',
53 'F_' => 'Financiƫn - ',
54 'IM_' => 'Infrastructuur en Milieu - ',
55 'OCW_' => 'Onderwijs, Cultuur en Wetenschap - ',
56 'SZW_' => 'Sociale Zaken en Werkgelegenheid - ',
57 'VJ_' => 'Veiligheid en Justitie - ',
58 'VWS_' => 'Volksgezondheid, Welzijn en Sport - ',
59 'J_' => 'Justitie - ',
60 'WWI_' => 'Wonen, Wijken en Integratie - ',
61 'JG_' => 'Jeugd en Gezin - ',
62 );
63
64 $search = array("RO_", "_Logo_Homepage");
65 $replacements = array("", "");
66
67 $logofiles = array();
68 foreach ($filesdir as $key => $value) {
69 $newindex = str_replace($search, $replacements, $key);
70 $logofiles[$path . '/' . $value->filename] = str_replace(array_keys($search_replacements), array_values($search_replacements), $newindex);
71 }
72
73 return $logofiles;
74 }
75
76 /**
77 * Format a color checkbox label on the admin screen.
78 *
79 * @param string $colour
80 * The name of the colour
81 *
82 * @return string
83 * A string containing the rendered label.
84 */
85 function _rijkshuisstijl_format_color_swatch($colour) {
86 return "<span class=\"" . $colour . "\">" . $colour . "</span>";
87 }
88
89 /**
90 * Initialized the Starterskit library, otherwise display an error.
91 *
92 * @return array
93 * The starterskit library as associative array.
94 */
95 function _rijkshuisstijl_init_starterskit() {
96 if (!module_exists('libraries') || !($library = libraries_load('starterskit')) || empty($library['loaded'])) {
97 drupal_set_message(t('The Starterskit library cannot be loaded. Please make sure that it exists before using the Rijkshuisstijl theme.'), 'error', FALSE);
98 return NULL;
99 }
100
101 return $library;
102 }