├── user_guide
└── highcharts_help.html
├── README.md
├── config
└── highcharts.php
├── helpers
└── analytics_helper.php
├── views
└── charts.php
├── controllers
└── charts.php
└── libraries
└── highcharts.php
/user_guide/highcharts_help.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/natanfelles/codeigniter-highcharts-library/master/README.md
--------------------------------------------------------------------------------
/config/highcharts.php:
--------------------------------------------------------------------------------
1 | array(
6 | 'backgroundColor' => array(
7 | 'linearGradient' => array(0, 0, 500, 500),
8 | 'stops' => array(
9 | array(0, 'rgb(255, 255, 255)'),
10 | array(1, 'rgb(240, 240, 255)')
11 | )
12 | ),
13 | 'shadow' => true
14 | )
15 | );
16 |
17 | // Template Example
18 | $config['chart_template'] = array(
19 | 'chart' => array(
20 | 'renderTo' => 'graph',
21 | 'defaultSeriesType' => 'column',
22 | 'backgroundColor' => array(
23 | 'linearGradient' => array(0, 500, 0, 0),
24 | 'stops' => array(
25 | array(0, 'rgb(255, 255, 255)'),
26 | array(1, 'rgb(190, 200, 255)')
27 | )
28 | ),
29 | ),
30 | 'colors' => array(
31 | '#ED561B', '#50B432'
32 | ),
33 | 'credits' => array(
34 | 'enabled'=> true,
35 | 'text' => 'highcharts library on GitHub',
36 | 'href' => 'https://github.com/ronan-gloo/codeigniter-highcharts-library'
37 | ),
38 | 'title' => array(
39 | 'text' => 'Template from config file'
40 | ),
41 | 'legend' => array(
42 | 'enabled' => false
43 | ),
44 | 'yAxis' => array(
45 | 'title' => array(
46 | 'text' => 'population'
47 | )
48 | ),
49 | 'xAxis' => array(
50 | 'title' => array(
51 | 'text' => 'Countries'
52 | )
53 | ),
54 | 'tooltip' => array(
55 | 'shared' => true
56 | )
57 | );
--------------------------------------------------------------------------------
/helpers/analytics_helper.php:
--------------------------------------------------------------------------------
1 | metrics);
14 |
15 | list($year, $month, $day) = explode('-', $object['summary']->startDate);
16 | $timestamp = mktime(0, 0, 0, $month, ($day + 1), $year).'000';
17 |
18 | foreach ($metrics as $metric)
19 | {
20 | $data[$metric]['pointInterval'] = 24 * 3600 * 1000;
21 | $data[$metric]['pointStart'] = $timestamp;
22 | $data[$metric]['name'] = $metric;
23 | $data[$metric]['data'] = data_array($metric, $object);
24 | }
25 | return $data;
26 | }
27 |
28 | /**
29 | * data_array function.
30 | *
31 | * @access public
32 | * @param mixed $string
33 | * @param mixed $array
34 | * @param mixed array &$result. (default: null)
35 | * @return array
36 | */
37 | function data_array($string, $array, array &$result = null)
38 | {
39 | if (is_null($result)) $result = array();
40 |
41 | foreach ($array as $key => $value)
42 | {
43 | if ($key != 'summary')
44 | {
45 | if ($key == $string && !is_object($value))
46 | {
47 | $result[] = (float)$value;
48 | }
49 | else if (is_object($value))
50 | {
51 | data_array($string, $value, $result);
52 | }
53 | }
54 | }
55 | return $result;
56 | }
57 |
--------------------------------------------------------------------------------
/views/charts.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Highcharts lib examples
6 |
27 |
28 |
31 |
32 |
33 |
34 |
44 |
45 |
46 |
47 |
48 |
Json string output: associative array with global options and 'local options' (for each graph)
49 |
50 |
51 |
Array output: associative array with global options and 'local options' (for each graph)
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/controllers/charts.php:
--------------------------------------------------------------------------------
1 | load->helper('url');
10 |
11 | $data['home'] = strtolower(__CLASS__).'/';
12 | $this->load->vars($data);
13 | }
14 |
15 |
16 | /**
17 | * index function.
18 | * Very basic example: juste draw some data
19 | */
20 | function index()
21 | {
22 | // simple highcharts example
23 | $this->load->library('highcharts');
24 |
25 | // some data series
26 | $serie['data'] = array(20, 45, 60, 22, 6, 36);
27 |
28 | $data['charts'] = $this->highcharts->set_serie($serie)->render();
29 |
30 | $this->load->view('charts', $data);
31 |
32 | }
33 |
34 |
35 | /**
36 | * categories function.
37 | * Lets go for a real world example
38 | */
39 | function categories()
40 | {
41 |
42 | $graph_data = $this->_data();
43 |
44 | $this->load->library('highcharts');
45 |
46 | $this->highcharts->set_type('column'); // drauwing type
47 | $this->highcharts->set_title('INTERNET WORLD USERS BY LANGUAGE', 'Top 5 Languages in 2010'); // set chart title: title, subtitle(optional)
48 | $this->highcharts->set_axis_titles('language', 'population'); // axis titles: x axis, y axis
49 |
50 | $this->highcharts->set_xAxis($graph_data['axis']); // pushing categories for x axis labels
51 | $this->highcharts->set_serie($graph_data['users']); // the first serie
52 | $this->highcharts->set_serie($graph_data['popul']); // second serie
53 |
54 | // we can user credits option to make a link to the source article.
55 | // it's possible to pass an object instead of array (but object will be converted to array by the lib)
56 | $credits->href = 'http://www.internetworldstats.com/stats7.htm';
57 | $credits->text = "Article on Internet Wold Stats";
58 | $this->highcharts->set_credits($credits);
59 |
60 | $this->highcharts->render_to('my_div'); // choose a specific div to render to graph
61 |
62 | $data['charts'] = $this->highcharts->render(); // we render js and div in same time
63 | $this->load->view('charts', $data);
64 | }
65 |
66 | /**
67 | * template function.
68 | * Load basic graph structure form template located in config file
69 | */
70 | function template()
71 | {
72 | $graph_data = $this->_data();
73 |
74 | $this->load->library('highcharts');
75 | $this->highcharts
76 | ->initialize('chart_template') // load template
77 | ->push_xAxis($graph_data['axis']) // we use push to not override template config
78 | ->set_serie($graph_data['users'])
79 | ->set_serie($graph_data['popul'], 'Another description'); // ovverride serie name
80 |
81 | // we want to display the second serie as sline. First parameter is the serie name
82 | $this->highcharts->set_serie_options(array('type' => 'spline'), 'Another description');
83 |
84 | $data['charts'] = $this->highcharts->render();
85 | $this->load->view('charts', $data);
86 | }
87 |
88 | /**
89 | * active_record function.
90 | * Example by passing data from AR result() (not result_array())
91 | *
92 | * @access public
93 | * @return void
94 | */
95 | function active_record()
96 | {
97 | $result = $this->_ar_data();
98 |
99 | // set data for conversion
100 | $dat1['x_labels'] = 'contries'; // optionnal, set axis categories from result row
101 | $dat1['series'] = array('users', 'population'); // set values to create series, values are result rows
102 | $dat1['data'] = $result;
103 |
104 | // just made some changes to display only one serie with custom name
105 | $dat2 = $dat1;
106 | $dat2['series'] = array('custom name' => 'users');
107 |
108 | $this->load->library('highcharts');
109 |
110 | // displaying muli graphs
111 | $this->highcharts->from_result($dat1)->add(); // first graph: add() register the graph
112 | $this->highcharts
113 | ->initialize('chart_template')
114 | ->set_dimensions('', 200) // dimension: width, height
115 | ->from_result($dat2)
116 | ->add(); // second graph
117 |
118 | $data['charts'] = $this->highcharts->render();
119 | $this->load->view('charts', $data);
120 | }
121 |
122 | /**
123 | * data_get function.
124 | * Output data as array on json string
125 | */
126 | function data_get()
127 | {
128 | $this->load->library('highcharts');
129 |
130 | // some data series
131 | $serie['data'] = array(20, 45, 60, 22, 6, 36);
132 | $this->highcharts->set_serie($serie);
133 |
134 | $data['array'] = $this->highcharts->get_array();
135 | $data['json'] = $this->highcharts->get(); // false to keep data (dont clear current options)
136 | $this->load->view('charts', $data);
137 |
138 | }
139 |
140 | /**
141 | * pie function.
142 | * Draw a Pie, and run javascript callback functions
143 | *
144 | * @access public
145 | * @return void
146 | */
147 | function pie()
148 | {
149 | $this->load->library('highcharts');
150 | $serie['data'] = array(
151 | array('value one', 20),
152 | array('value two', 45),
153 | array('other value', 60)
154 | );
155 | $callback = "function() { return ''+ this.point.name +': '+ this.y +' %'}";
156 |
157 | $tool->formatter = $callback;
158 | $plot->pie->dataLabels->formatter = $callback;
159 |
160 | $this->highcharts
161 | ->set_type('pie')
162 | ->set_serie($serie)
163 | ->set_tooltip($tool)
164 | ->set_plotOptions($plot);
165 |
166 | $data['charts'] = $this->highcharts->render();
167 | $this->load->view('charts', $data);
168 | }
169 |
170 |
171 | // HELPERS FUNCTIONS
172 | /**
173 | * _data function.
174 | * data for examples
175 | */
176 | function _data()
177 | {
178 | $data['users']['data'] = array(536564837, 444948013, 153309074, 99143700, 82548200);
179 | $data['users']['name'] = 'Users by Language';
180 | $data['popul']['data'] = array(1277528133, 1365524982, 420469703, 126804433, 250372925);
181 | $data['popul']['name'] = 'World Population';
182 | $data['axis']['categories'] = array('English', 'Chinese', 'Spanish', 'Japanese', 'Portuguese');
183 |
184 | return $data;
185 | }
186 |
187 | /**
188 | * _ar_data function.
189 | * simulate Active Record result
190 | */
191 | function _ar_data()
192 | {
193 | $data = $this->_data();
194 | foreach ($data['users']['data'] as $key => $val)
195 | {
196 | $output[] = (object)array(
197 | 'users' => $val,
198 | 'population' => $data['popul']['data'][$key],
199 | 'contries' => $data['axis']['categories'][$key]
200 | );
201 | }
202 | return $output;
203 | }
204 |
205 | }
206 |
207 | /* End of file welcome.php */
208 | /* Location: ./system/application/controllers/welcome.php */
--------------------------------------------------------------------------------
/libraries/highcharts.php:
--------------------------------------------------------------------------------
1 | 0) $this->initialize($config);
58 | }
59 |
60 | /**
61 | * initialize function.
62 | * load options form a config file or directelly from array.
63 | * If
64 | *
65 | * @access public
66 | * @param mixed $template
67 | * @param bool $config_file. (default: false)
68 | * @param string $config_path. (default: 'highcharts')
69 | * @return void
70 | */
71 | public function initialize($config = array(), $config_path = 'highcharts')
72 | {
73 | if (is_string($config)) // string means "load this template"
74 | {
75 | $ci =& get_instance();
76 | $ci->config->load($config_path);
77 |
78 | $config = $ci->config->item($config);
79 |
80 | if (count($config) > 0)
81 | {
82 | $this->opts = $this->set_local_options($config);
83 | }
84 |
85 | }
86 | if (isset($config['shared_options']) AND empty($this->shared_opts))
87 | {
88 | $this->shared_opts = $config['shared_options'];
89 | unset($config['shared_options']);
90 | }
91 |
92 | if (! isset($this->opts['series'])) $this->opts['series'] = array();
93 | if (! isset($this->opts['chart']['renderTo'])) $this->opts['chart']['renderTo'] = 'hc_chart';
94 |
95 | return $this;
96 | }
97 |
98 | /**
99 | * set_options function.
100 | * This function can set global options shared by your charts
101 | *
102 | * @access public
103 | * @param array $options. (default: array())
104 | * @return void
105 | */
106 | public function set_global_options($options = array())
107 | {
108 | if (! empty($options)) $this->shared_opts = $this->set_local_options($options);
109 |
110 | return $this;
111 | }
112 |
113 |
114 | /**
115 | * __call function.
116 | *
117 | * @access public
118 | * @param mixed $func
119 | * @param mixed $args
120 | * @return void
121 | */
122 | public function __call($func, $args)
123 | {
124 | if (strpos($func,'_'))
125 | {
126 | list($action, $type) = explode('_', $func);
127 |
128 | if (! isset($this->opts[$type]))
129 | {
130 | $this->opts[$type] = array();
131 | }
132 | switch ($action)
133 | {
134 | case 'set':
135 | $this->opts[$type] = $this->set_local_options($args[0]);
136 | break;
137 |
138 | case 'push':
139 | $this->opts[$type] += $this->set_local_options($args[0]);
140 | break;
141 |
142 | case 'unset':
143 | $this->unset_local_options($args, $type);
144 | break;
145 | }
146 | }
147 |
148 | return $this;
149 | }
150 |
151 | /**
152 | * set_options function.
153 | *
154 | * @access private
155 | * @param array $options. (default: array())
156 | * @param array $root. (default: array())
157 | * @return void
158 | */
159 | private function set_local_options($options = array(), $root = array())
160 | {
161 | foreach ($options as $opt_key => $opt_name)
162 | {
163 | if(is_string($opt_key))
164 | {
165 | if(is_object($opt_name))
166 | {
167 | $root[$opt_key] = array();
168 | $root[$opt_key] = $this->set_local_options($opt_name, $root[$opt_key]); // convert back to array
169 | }
170 | else $root[$opt_key] = $this->encode_function($opt_name);
171 | }
172 | }
173 | return $root;
174 | }
175 |
176 | /**
177 | * unset_options function.
178 | *
179 | * @access private
180 | * @param array $options. (default: array())
181 | * @param mixed $type
182 | * @return void
183 | */
184 | private function unset_local_options($options = array(), $type)
185 | {
186 | foreach ($options as $option)
187 | {
188 | if (array_key_exists($option, $this->opts[$type]))
189 | {
190 | unset($this->opts[$type][$option]);
191 | }
192 | }
193 | }
194 |
195 | // SHORTCUT FUNCTIONS
196 | // guessed most used parameters that desserves to be set quickly
197 | /**
198 | * set_title function.
199 | * set title and subtitle in one shoot
200 | *
201 | * @access public
202 | * @param string $title. (default: '')
203 | * @param array $options. (default: array())
204 | * @return void
205 | */
206 | public function set_title($title = '', $subtitle = '')
207 | {
208 | if ($title) $this->opts['title']['text'] = $title;
209 | if ($subtitle) $this->opts['subtitle']['text'] = $subtitle;
210 |
211 | return $this;
212 | }
213 |
214 | /**
215 | * set_axis_titles function.
216 | * quickly set x and y texts
217 | *
218 | * @access public
219 | * @param string $x_label. (default: '')
220 | * @param string $y_label. (default: '')
221 | * @return void
222 | */
223 | function set_axis_titles($x_title = '', $y_title = '')
224 | {
225 | if ($x_title) $this->opts['xAxis']['title']['text'] = $x_title;
226 | if ($y_title) $this->opts['yAxis']['title']['text'] = $y_title;
227 |
228 | return $this;
229 | }
230 |
231 | /**
232 | * render_to function.
233 | * set the container's id to render the graph
234 | *
235 | * @access public
236 | * @param string $id. (default: '')
237 | * @return void
238 | */
239 | public function render_to($id = '')
240 | {
241 | $this->opts['chart']['renderTo'] = $id;
242 |
243 | return $this;
244 | }
245 |
246 | /**
247 | * set_type function.
248 | * The default series type for the chart
249 | *
250 | * @access public
251 | * @param string $type. (default: '')
252 | * @return void
253 | */
254 | public function set_type($type = '')
255 | {
256 | if ($type AND is_string($type)) $this->opts['chart']['type'] = $type;
257 |
258 | return $this;
259 | }
260 |
261 | /**
262 | * set_dimensions function.
263 | * fastly set dimension of the graph is desired
264 | *
265 | * @access public
266 | * @param mixed $width. (default: null)
267 | * @param mixed $height. (default: null)
268 | * @return void
269 | */
270 | public function set_dimensions($width = null, $height = null)
271 | {
272 | if ($width) $this->opts['chart']['width'] = (int)$width;
273 | if ($height) $this->opts['chart']['height'] = (int)$height;
274 |
275 | return $this;
276 | }
277 |
278 | /**
279 | * set_serie function.
280 | *
281 | * @access public
282 | * @param string $s_serie_name. (default: '')
283 | * @param array $a_value. (default: array())
284 | * @return void
285 | */
286 | public function set_serie($options = array(), $serie_name = '')
287 | {
288 | if ( ! $serie_name AND ! isset($options['name']))
289 | {
290 | $serie_name = count($this->opts['series']);
291 | }
292 | // override with the serie name passed
293 | else if ($serie_name AND isset($options['name']))
294 | {
295 | $options['name'] = $serie_name;
296 | }
297 |
298 | $index = $this->find_serie_name($serie_name);
299 |
300 | if (count($options) > 0)
301 | {
302 | foreach($options as $key => $value)
303 | {
304 | $value = (is_numeric($value)) ? (float)$value : $value;
305 | $this->opts['series'][$index][$key] = $value;
306 | }
307 | }
308 | return $this;
309 | }
310 |
311 | /**
312 | * set_serie_option function.
313 | * We are settings each serie options for graph
314 | *
315 | * @access public
316 | * @param string $s_serie_name. (default: '')
317 | * @param string $s_option. (default: '')
318 | * @param string $value. (default: '')
319 | * @return void
320 | */
321 | public function set_serie_options($options = array(), $serie_name = '')
322 | {
323 | if ($serie_name AND count($options) > 0)
324 | {
325 | $index = $this->find_serie_name($serie_name);
326 |
327 | foreach ($options as $key => $opt)
328 | {
329 | $this->opts['series'][$index][$key] = $opt;
330 | }
331 | }
332 | return $this;
333 | }
334 |
335 | /**
336 | * push_serie_data function.
337 | *
338 | * @access public
339 | * @param string $s_serie_name. (default: '')
340 | * @param string $s_value. (default: '')
341 | * @return void
342 | */
343 | public function push_serie_data($value = '', $serie_name = ''){
344 |
345 | if ($serie_name AND $value)
346 | {
347 | $index = $this->find_serie_name($serie_name);
348 |
349 | $value = (is_numeric($value)) ? (float)$value : $value;
350 |
351 | $this->opts['series'][$index]['data'][] = $value;
352 | }
353 | return $this;
354 | }
355 |
356 |
357 | /**
358 | * find_serie_name function.
359 | * fonction qui permet de savoir si une série existe
360 | *
361 | * @access private
362 | * @return void
363 | */
364 | private function find_serie_name($name)
365 | {
366 | $tot_indexes = count($this->opts['series']);
367 |
368 | if ($tot_indexes > 0)
369 | {
370 | foreach($this->opts['series'] as $index => $serie)
371 | {
372 | if (isset($serie['name']) AND strtolower($serie['name']) == strtolower($name))
373 | {
374 | return $index;
375 | }
376 | }
377 | }
378 |
379 | $this->opts['series'][$tot_indexes]['name'] = $name;
380 |
381 | return $tot_indexes;
382 | }
383 |
384 |
385 | /**
386 | * push_categorie function.
387 | * Add custom name to axes.
388 | *
389 | * @access public
390 | * @param mixed $value
391 | * @return void
392 | */
393 | public function push_categorie($value, $axis = 'x')
394 | {
395 | if(trim($value)!= '') $this->opts[$axis.'Axis']['categories'][] = $value;
396 |
397 | return $this;
398 | }
399 |
400 |
401 |
402 | // AUTOMATIC DATABASE RENDERING
403 | /**
404 | * from_result function.
405 | *
406 | * @access public
407 | * @param array $data. (default: array())
408 | * @return void
409 | */
410 | public function from_result($data = array())
411 | {
412 | if (! isset($this->opts['series']))
413 | {
414 | $this->opts['series'] = array();
415 | }
416 |
417 | foreach ($data['data'] as $row)
418 | {
419 | if (isset($data['x_labels'])) $this->push_categorie($row->$data['x_labels'],'x');
420 | if (isset($data['y_labels'])) $this->push_categorie($row->$data['y_labels'],'y');
421 |
422 | foreach ($data['series'] as $name => $value)
423 | {
424 | // there is no options, juste assign name / value pair
425 | if (is_string($value))
426 | {
427 | $text = (is_string($name)) ? $name : $value;
428 | $dat = $row->$value;
429 | }
430 |
431 | // options are passed
432 | else if (is_array($value))
433 | {
434 | if (isset($value['name']))
435 | {
436 | $text = $value['name'];
437 | unset($value['name']);
438 | }
439 | else
440 | {
441 | $text = $value['row'];
442 | }
443 | $dat = $row->{$value['row']};
444 | unset($value['row']);
445 |
446 | $this->set_serie_options($value, $text);
447 | }
448 |
449 | $this->push_serie_data($dat, $text);
450 | }
451 | }
452 | return $this;
453 | }
454 |
455 |
456 |
457 | /**
458 | * add function.
459 | * If options is a string, then the index of the current
460 | * options to store it
461 | *
462 | * @access public
463 | * @param array $options. (default: array())
464 | * @return void
465 | */
466 | public function add($options = array(), $clear = true)
467 | {
468 | if (count($this->global_opts) <= self::$chart_id AND ! empty($this->opts['series']))
469 | {
470 | if (is_string($options) AND trim($options) !== '')
471 | {
472 | $this->global_opts[$options] = $this->opts;
473 | }
474 | else
475 | {
476 | $this->global_opts[self::$chart_id] = (count($options)> 0) ? $options : $this->opts;
477 | }
478 | }
479 |
480 | self::$chart_id++;
481 |
482 | if ($clear === true) $this->clear();
483 |
484 | return $this;
485 | }
486 |
487 |
488 | /**
489 | * get function.
490 | * return the global options array as json string
491 | *
492 | * @access public
493 | * @return void
494 | */
495 | public function get($clear = true)
496 | {
497 | $this->add();
498 |
499 | foreach ($this->global_opts as $key => $opts)
500 | {
501 | $this->global_opts[$key] = $this->encode($opts);
502 | }
503 |
504 | return $this->process_get($this->global_opts, $clear, 'json');
505 | }
506 |
507 | /**
508 | * get_array function.
509 | * return the raw options array
510 | *
511 | * @access public
512 | * @return void
513 | */
514 | public function get_array($clear = true)
515 | {
516 | $this->add();
517 |
518 | return $this->process_get($this->global_opts, $clear, 'array');
519 | }
520 |
521 | /**
522 | * encode function.
523 | * Search and replace delimited functions by encode_function()
524 | * We need to remove quotes from json string in order to
525 | * make javascript function works.
526 | *
527 | * @access public
528 | * @param mixed $options
529 | * @return void
530 | */
531 | public function encode($options)
532 | {
533 | $options = str_replace('\\', '', json_encode($options));
534 | return str_replace($this->replace_keys, $this->orig_keys, $options);
535 | }
536 |
537 | /**
538 | * process_get function.
539 | * This functon send the output for get() and get_array().
540 | * it will return an associative array if some global variables are defined.
541 | *
542 | * @access private
543 | * @param mixed $options
544 | * @param mixed $clear
545 | * @return Json / Array
546 | */
547 | private function process_get($options, $clear, $type)
548 | {
549 | if (count($this->shared_opts) > 0)
550 | {
551 | $global = ($type == 'json') ? $this->encode($this->shared_opts) : $this->shared_opts;
552 |
553 | $options = array('global' => $global, 'local' => $options);
554 | }
555 |
556 | if ($clear === true) $this->clear();
557 |
558 | return $options;
559 | }
560 |
561 | /**
562 | * get_embed function.
563 | * Return javascript embedable code and friend div
564 | *
565 | * @access public
566 | * @return void
567 | */
568 | public function render()
569 | {
570 | $this->add();
571 |
572 | $i = 1; $d = 1; $divs = '';
573 |
574 | $embed = ''."\n";
597 | $embed .= $divs;
598 |
599 | $this->clear();
600 |
601 | return $embed;
602 | }
603 |
604 |
605 | /**
606 | * clear function.
607 | * clear instance properties. Very general at the moment, should only reset
608 | * desired vars when lib will be finish
609 | *
610 | * @access public
611 | * @return void
612 | */
613 | public function clear($shared = false)
614 | {
615 | $this->opts = array();
616 | $this->opts['series'] = array();
617 | $this->opts['chart']['renderTo'] = 'hc_chart';
618 | $this->serie_index = 0;
619 |
620 | if ($shared === true) $this->shared_opts = array();
621 |
622 | return $this;
623 | }
624 |
625 | /**
626 | * encode_functions function.
627 | * We are looking for javascript functions and delimit them
628 | *
629 | * @access private
630 | * @param mixed $array
631 | * @return void
632 | */
633 | private function encode_function($array = array())
634 | {
635 | if (is_string($array)) {
636 | $array = $this->delimit_function($array);
637 | }
638 | else {
639 | foreach($array as $key => $value) {
640 | if (is_array($value)) {
641 | $this->encode_function($value);
642 | }
643 | else {
644 | $array[$key] = $this->delimit_function($value);
645 | }
646 | }
647 | }
648 | return $array;
649 | }
650 |
651 | /**
652 | * delimit_function function.
653 | * 'Tag' javascript functions
654 | *
655 | * @access private
656 | * @param string $string. (default: '')
657 | * @return void
658 | */
659 | private function delimit_function($string = '')
660 | {
661 | if(strpos($string, 'function(') !== false)
662 | {
663 | $this->orig_keys[] = $string;
664 | $string = '$$' . $string . '$$';
665 | $this->replace_keys[] = '"' . $string . '"';
666 | }
667 | return $string;
668 | }
669 |
670 | }
--------------------------------------------------------------------------------