Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Charts plugin
- *
- * @package Monstra
- * @subpackage Plugins
- * @author Romanenko Sergey / Awilum
- * @copyright 2012 Romanenko Sergey / Awilum
- * @version 1.0.0
- *
- */
- // Register plugin
- Plugin::register( __FILE__,
- __('Charts'),
- __('Charts plugin for Monstra.'),
- '1.0.0',
- 'Awilum',
- 'http://monstra.org');
- // Add hook
- Action::add('theme_header', 'Charts::themesHeaders');
- // Add shortcode
- Shortcode::add('chart', 'Charts::_shortcode');
- /**
- * Charts Shortcode
- *
- * <code>
- * {chart data="Mushrooms,3|Zucchini,5|Pepperoni,1"}
- *
- * {chart width="640" height="480" data="Mushrooms,3|Zucchini,5|Pepperoni,1"}
- *
- * {chart width="640" height="480" title="How Much Pizza I Ate Last Night" data="Mushrooms,3|Zucchini,5|Pepperoni,1"}
- *
- * {chart width="640" height="480" title="How Much Pizza I Ate Last Night" type="bar" data="Mushrooms,3|Zucchini,5|Pepperoni,1"}
- * </code>
- *
- */
- class Charts {
- /**
- * Charts Headers
- */
- public static function themesHeaders() {
- echo ('');
- }
- /**
- * Charts Shortcode
- */
- public static function _shortcode($attributes) {
- // Extract
- extract($attributes);
- // UID
- $uid = Text::random();
- // Data
- if (isset($data)) {
- $data_string = '';
- $_data = explode('|', $data);
- foreach($_data as $d) {
- $part = explode(',', $d);
- $data_string .= '["'.$part[0].'", '.$part[1].'],';
- }
- $data = $data_string;
- } else {
- $data = '["test", 1],';
- }
- // Title
- if (isset($title)) $title = $title; else $title = 'Charts';
- // Type
- if (isset($type) && ($type == 'pie' || $type == 'bar')) $type = $type; else $type = 'pie';
- // Width
- if (isset($width)) $width = $width; else $width = 400;
- // Height
- if (isset($height)) $height = $height; else $height = 300;
- // Chart
- return ('
- <script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <script type="text/javascript">
- google.load("visualization", "1.0", {"packages":["corechart"]});
- google.setOnLoadCallback(drawChart_'.$uid.');
- function drawChart_'.$uid.'() {
- var data = new google.visualization.DataTable();
- data.addColumn("string", "Topping");
- data.addColumn("number", "Slices");
- data.addRows([
- '.$data.'
- ]);
- var options = {\'title\':\''.$title.'\',
- \'width\':'.(int)$width.',
- \'height\':'.(int)$height.'};
- var chart = new google.visualization.'.ucfirst($type).'Chart(document.getElementById(\'chart_div_'.$uid.'\'));
- chart.draw(data, options);
- }
- </script>
- <div id="chart_div_'.$uid.'"></div>');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement