/[drupal]/contributions/modules/carto/carto.inc
ViewVC logotype

Contents of /contributions/modules/carto/carto.inc

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


Revision 1.13 - (show annotations) (download) (as text)
Fri Sep 29 14:34:22 2006 UTC (3 years, 1 month ago) by openwereld
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +12 -26 lines
File MIME type: text/x-php
First updates for Drupal 5.x api.
1 <?php
2 // $Id: carto.inc,v 1.12 2006/09/29 08:19:42 openwereld Exp $
3
4 /**
5 * These are the functions to be defined only when module is enabled.
6 * Otherwise they could mess up with the admin system
7 */
8
9 $carto_config_path = drupal_get_path('module','carto') . '/config.inc';
10 if( file_exists( $carto_config_path ) )
11 {
12 include $carto_config_path;
13
14 // override carto variables
15 if( defined( 'SMARTY_DIR' ) )
16 variable_set( 'carto_smarty_dir', SMARTY_DIR );
17 if( defined( 'MAPPINGWIDGETS_DIR' ) )
18 variable_set( 'carto_mappingwidgets_dir', MAPPINGWIDGETS_DIR );
19 if( defined( 'MAPPINGWIDGETS_BASE_URI' ) )
20 {
21 $value = MAPPINGWIDGETS_BASE_URI;
22 if( strpos( $value, base_path() ) === 0 )
23 {
24 // remove base_path from MAPPINGWIDGETS_BASE_URI
25 $value = substr( $value, strlen(base_path()) );
26 }
27 variable_set( 'carto_mappingwidgets_base_uri', $value );
28 }
29 }
30
31 if( ! defined('SMARTY_DIR') )
32 {
33 $value = variable_get('carto_smarty_dir','');
34 if( file_exists( $value . 'Smarty.class.php' ) )
35 {
36 define( "SMARTY_DIR", $value );
37 }
38 else if( is_dir( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR ) )
39 {
40 // smarty installed under carto module
41 define( "SMARTY_DIR", dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR );
42 }
43 else
44 {
45 // default (for Debian Linux)
46 define( 'SMARTY_DIR', '/usr/share/php/smarty/libs/' );
47 }
48 }
49
50 if( ! defined('MAPPINGWIDGETS_DIR') )
51 {
52 $value = variable_get('carto_mappingwidgets_dir','');
53 if( file_exists( $value . 'MappingWidgets.php' ) )
54 {
55 define( "MAPPINGWIDGETS_DIR", $value );
56 }
57 else if( is_dir( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'mappingwidgets' . DIRECTORY_SEPARATOR ) )
58 {
59 // mappingwidgets installed under carto module
60 define( "MAPPINGWIDGETS_DIR", dirname(__FILE__) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'mappingwidgets' . DIRECTORY_SEPARATOR );
61 }
62 else
63 {
64 // default (for Debian Linux)
65 define( "MAPPINGWIDGETS_DIR", "/usr/local/share/mappingwidgets/" );
66 }
67 }
68
69 if( ! defined('MAPPINGWIDGETS_BASE_URI') )
70 {
71 $value = variable_get('carto_mappingwidgets_base_uri','');
72 global $base_url;
73 if( $value != '' )
74 {
75 define( "MAPPINGWIDGETS_BASE_URI", base_path() . $value );
76 }
77 else
78 {
79 define( 'MAPPINGWIDGETS_BASE_URI', base_path() . 'modules/carto/lib/mappingwidgets/htdocs/' );
80 }
81 }
82
83 if( file_exists(variable_get('carto_mappingwidgets_dir',MAPPINGWIDGETS_DIR) . 'MappingWidgets.php')
84 && file_exists(variable_get('carto_smarty_dir',SMARTY_DIR) . 'Smarty.class.php' ) )
85 {
86 // load configuration for current Drupal site
87 if( ($path = drupal_get_filename( 'config', 'carto' )) )
88 require_once( $path );
89
90 require_once( variable_get('carto_mappingwidgets_dir',MAPPINGWIDGETS_DIR) . 'MappingWidgets.php' );
91
92 class CartoMapper extends SmartyMapping
93 {
94 function CartoMapper( )
95 {
96 // use current drupal locale
97 global $locale;
98
99 $this->SmartyMapping( $locale );
100
101 // register selected carto widgets
102 if( file_exists( dirname(__FILE__) . '/widgets/' ) )
103 {
104 $count = $this->registerWidgetPath( dirname(__FILE__) . '/widgets/' );
105 //print 'register count=' . $count . '<br/>';
106 }
107
108 // add carto skin (name, path, and uri)
109 $this->addSkin( 'carto'
110 , dirname(__FILE__) . 'skin'
111 , base_path() . 'modules/carto/skin/' );
112
113 $this->caching = (variable_get('carto_enable_smarty_caching','1') == '1' ? true : false);
114 $this->force_compile = (variable_get('carto_smarty_force_compile','0') == '1' ? true : false);
115 /* *
116 print 'carto info | locale=' . $locale
117 . ' | path=' . drupal_get_path_alias($_GET['q'])
118 . ' | caching=' . $this->caching
119 . '<br />'
120 . MAPPINGWIDGETS_COMPILE_DIR
121 ;
122 /* */
123 $this->set_html_head( );
124
125 // register the resource name "carto"
126 $this->register_resource( "carto"
127 , array( "carto_get_template",
128 "carto_get_timestamp",
129 "carto_get_secure",
130 "carto_get_trusted" ) );
131 }
132
133 function set_html_head( )
134 {
135 // todo: put this somewhere else in drupal 5.0?
136 drupal_add_css( variable_get('carto_mappingwidgets_base_uri',substr(MAPPINGWIDGETS_BASE_URI,strlen(base_path())))
137 . 'skins/default/styles/mappingwidgets.css' );
138 drupal_add_css( drupal_get_path('module','carto') . "/carto.css" );
139
140 $output = "\n";
141 $output .= "<meta http-equiv=\"imagetoolbar\" content=\"no\" />\n";
142 return drupal_set_html_head( $output );
143 }
144
145 /**
146 * To be called by Smarty output filter to translate
147 * mappingwidgets codes into texts for current locale.
148 * NB: mappingwidgets keys in drupal's locale tables
149 * are prefixed by '#'.
150 */
151 function getTranslation( $key )
152 {
153 $text = t('#' . $key);
154 if( $text != '#' . $key )
155 {
156 return $text;
157 }
158 else
159 {
160 // try to get value from mappingwidgets
161 return $GLOBALS['_NG_LANGUAGE_']->getTranslation( $key );
162 }
163 }
164
165 } // class CartoMapper
166
167 function get_carto_mapper( )
168 {
169 if( ! isset( $GLOBALS['cartoSmarty'] ) )
170 {
171 $GLOBALS['cartoSmarty'] = & new CartoMapper();
172 }
173 return $GLOBALS['cartoSmarty'];
174 }
175 }
176
177 function carto_get_template( $tpl_name, &$tpl_source, &$smarty_obj )
178 {
179 // do database call here to fetch your template,
180 // populating $tpl_source
181 $sql = "select content from {carto_filter_blocks} where cfid = '%s'";
182 $result = db_query( $sql, $tpl_name );
183 if( db_num_rows( $result ) > 0 )
184 {
185 $item = db_fetch_object( $result );
186 $tpl_source = $item->content;
187 return true;
188 }
189 else
190 {
191 return false;
192 }
193 }
194
195 function carto_get_timestamp( $tpl_name, &$tpl_timestamp, &$smarty_obj )
196 {
197 // do database call here to populate $tpl_timestamp.
198 $sql = "select time from {carto_filter_blocks} where cfid = '%s'";
199 $result = db_query( $sql, $tpl_name );
200 if( db_num_rows( $result ) > 0 )
201 {
202 $item = db_fetch_object( $result );
203 $tpl_timestamp = $item->time;
204 return true;
205 }
206 else
207 {
208 return false;
209 }
210 }
211
212
213 function carto_get_secure( $tpl_name, &$smarty_obj )
214 {
215 // assume all templates are secure
216 return true;
217 }
218
219
220 function carto_get_trusted( $tpl_name, &$smarty_obj )
221 {
222 // not used for templates
223 }
224
225 ?>

  ViewVC Help
Powered by ViewVC 1.1.2