/[drupal]/contributions/modules/geshifilter/geshifilter.install
ViewVC logotype

Contents of /contributions/modules/geshifilter/geshifilter.install

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


Revision 1.9 - (show annotations) (download) (as text)
Sat Jul 4 11:05:56 2009 UTC (4 months, 3 weeks ago) by soxofaan
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +45 -1 lines
File MIME type: text/x-php
merged PHP style code block option with tag style option
1 <?php
2 // $Id: geshifilter.install,v 1.8 2009/07/04 09:48:59 soxofaan Exp $
3
4 /**
5 * @file
6 * Installation and uninstallation functions for the GeSHi filter.
7 */
8
9 /**
10 * Implementation of hook_install
11 */
12 function geshifilter_install() {
13 // Enable some popular languages and set their language tags by default
14 $languages = array('php', 'drupal5', 'drupal6', 'javascript', 'java', 'c', 'cpp', 'python', 'ruby');
15 foreach ($languages as $language) {
16 variable_set('geshifilter_language_enabled_' . $language, TRUE);
17 variable_set('geshifilter_language_tags_' . $language, '<' . $language . '>');
18 }
19
20 // what to do next?
21 drupal_set_message(t('GeSHi filter is installed. You should now <a href="!geshi_admin">configure the GeSHi filter</a> and enable it in the desired <a href="!input_formats">input formats</a>.',
22 array('!geshi_admin' => url('admin/settings/geshifilter'), '!input_formats' => url('admin/settings/filters'))
23 ));
24 }
25
26 /**
27 * On uninstall: remove module variables and clear variable cache
28 */
29 function geshifilter_uninstall() {
30 db_query("DELETE FROM {variable} WHERE name LIKE 'geshifilter_%'");
31 cache_clear_all('variables', 'cache');
32 }
33
34 /**
35 * Implementation of hook_update_N().
36 */
37 function geshifilter_update_1() {
38 // clear the cache of available languages
39 variable_del('geshifilter_available_languages');
40 return array();
41 }
42
43 /**
44 * Implementation of hook_update_N().
45 *
46 * Upgrade path from usage of geshifilter_brackets variable
47 * to geshifilter_tag_styles variable.
48 */
49 function geshifilter_update_6001() {
50 _geshifilter_update_6001_brackets_to_tag_styles(NULL);
51 foreach (filter_formats() as $format => $input_format) {
52 _geshifilter_update_6001_brackets_to_tag_styles($format);
53 }
54 return array();
55 }
56
57 /**
58 * Helper function for updating the old geshifilter_brackets variables
59 * to geshifilter_tag_styles variables.
60 * @param $format NULL (for global variable) or input format id.
61 */
62 function _geshifilter_update_6001_brackets_to_tag_styles($format) {
63 // Make $format a suffix for usage in variable name.
64 $format = isset($format) ? "_{$format}" : '';
65 // Try to fetch the variable value and convert it if found.
66 $geshifilter_brackets = variable_get('geshifilter_brackets'. $format, NULL);
67 if (isset($geshifilter_brackets)) {
68 switch ($geshifilter_brackets) {
69 case GESHIFILTER_BRACKETS_ANGLE:
70 case GESHIFILTER_BRACKETS_SQUARE:
71 variable_set('geshifilter_tag_styles'. $format, array(
72 $geshifilter_brackets => $geshifilter_brackets
73 ));
74 break;
75 case GESHIFILTER_BRACKETS_BOTH:
76 variable_set('geshifilter_tag_styles'. $format, array(
77 GESHIFILTER_BRACKETS_ANGLE => GESHIFILTER_BRACKETS_ANGLE,
78 GESHIFILTER_BRACKETS_SQUARE => GESHIFILTER_BRACKETS_SQUARE,
79 ));
80 break;
81 }
82 // Remove old variable.
83 variable_del('geshifilter_brackets'. $format);
84 }
85 }
86
87 /**
88 * Implementation of hook_update_N().
89 *
90 * Upgrade path for merging of geshifilter_enable_php_delimiters
91 * into to the geshifilter_tag_styles variable.
92 */
93 function geshifilter_update_6002() {
94 _geshifilter_update_6002_php_delimter_into_tag_styles(NULL);
95 foreach (filter_formats() as $format => $input_format) {
96 _geshifilter_update_6002_php_delimter_into_tag_styles($format);
97 }
98 return array();
99 }
100
101 /**
102 * Helper function for merging old geshifilter_enable_php_delimiters
103 * into geshifilter_tag_styles variables.
104 * @param $format NULL (for global variable) or input format id.
105 */
106 function _geshifilter_update_6002_php_delimter_into_tag_styles($format) {
107 // Load geshifilter.inc because we need _geshifilter_tag_styles().
108 require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.inc';
109
110 // Make $format a suffix for usage in variable name.
111 $format = isset($format) ? "_{$format}" : '';
112 // Try to fetch the variable value and convert it if found.
113 $geshifilter_enable_php_delimiters = variable_get('geshifilter_enable_php_delimiters'. $format, NULL);
114 if (isset($geshifilter_enable_php_delimiters)) {
115 // First get the current value of the geshifilter_tag_styles variable.
116 $geshifilter_brackets = _geshifilter_tag_styles($format);
117 // Insert value for PHP style code blocks
118 if ($geshifilter_enable_php_delimiters) {
119 $geshifilter_brackets[GESHIFILTER_BRACKETS_PHPBLOCK] = GESHIFILTER_BRACKETS_PHPBLOCK;
120 }
121 else {
122 $geshifilter_brackets[GESHIFILTER_BRACKETS_PHPBLOCK] = 0;
123 }
124 // Save the new settings.
125 variable_set('geshifilter_tag_styles'. $format, $geshifilter_brackets);
126 // Remove old variable.
127 variable_del('geshifilter_enable_php_delimiters'. $format);
128 }
129 }

  ViewVC Help
Powered by ViewVC 1.1.2