Open Flash Plugin for Codeigniter

I created a new OPEN FLASH GRAPH CHART plugin for codeigniter, just in case you want to add a graph chart in your codeigniter framework.

Hope it helps!

1. download the OPEN FLASH GRAPH CHART:
http://teethgrinder.co.uk/open-flash-chart/

Extract the downloaded file and save the graph.php class into your System/Libraries folder and rename it to opgraph.php. Modify and update this code:

		$this->js_path = 'javascripts/';
		$this->swf_path = 'swf/';

Save the swfobject.js file into your javascripts folder and open-flash-chart.swf into your swf folder

2. Save this code into your System/plugins/graph_pi.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function open_flash_chart_object_str( $width, $height, $url, $use_swfobject=true, $base='' )
{
    //
    // return the HTML as a string
    //
    return _ofc( $width, $height, $url, $use_swfobject, $base );
}

function open_flash_chart_object( $width, $height, $url, $use_swfobject=true, $base='' )
{
    //
    // stream the HTML into the page
    //
    echo _ofc( $width, $height, $url, $use_swfobject, $base );
}

function _ofc( $width, $height, $url, $use_swfobject, $base )
{
    //
    // I think we may use swfobject for all browsers,
    // not JUST for IE...
    //
    //$ie = strstr(getenv('HTTP_USER_AGENT'), 'MSIE');

    //
    // escape the & and stuff:
    //
    $url = urlencode($url);

    //
    // output buffer
    //
    $out = array();

    //
    // check for http or https:
    //
    if (isset ($_SERVER['HTTPS']))
    {
        if (strtoupper ($_SERVER['HTTPS']) == 'ON')
        {
            $protocol = 'https';
        }
        else
        {
            $protocol = 'http';
        }
    }
    else
    {
        $protocol = 'http';
    }

    //
    // if there are more than one charts on the
    // page, give each a different ID
    //
    global $open_flash_chart_seqno;
    $obj_id = 'chart';
    $div_name = 'flashcontent';

    //$out[] = '<script type="text/javascript" src="'. $base .'javascripts/ofc.js"></script>';

    if( !isset( $open_flash_chart_seqno ) )
    {
        $open_flash_chart_seqno = 1;
        $out[] = '<script type="text/javascript" src="'. $base .'javascripts/swfobject.js"></script>';
    }
    else
    {
        $open_flash_chart_seqno++;
        $obj_id .= '_'. $open_flash_chart_seqno;
        $div_name .= '_'. $open_flash_chart_seqno;
    }

    if( $use_swfobject )
    {
	// Using library for auto-enabling Flash object on IE, disabled-Javascript proof
    $out[] = '<div id="'. $div_name .'"></div>';
	$out[] = '<script type="text/javascript">';
	$out[] = 'var so = new SWFObject("'. $base .'swf/open-flash-chart.swf", "'. $obj_id .'", "'. $width . '", "' . $height . '", "9", "#FFFFFF");';
	//$out[] = 'so.addVariable("width", "' . $width . '");';
	//$out[] = 'so.addVariable("height", "' . $height . '");';
	$out[] = 'so.addVariable("data", "'. $url . '");';
	$out[] = 'so.addParam("allowScriptAccess", "sameDomain");';
	$out[] = 'so.write("'. $div_name .'");';
	$out[] = '</script>';
	$out[] = '<noscript>';
    }

    $out[] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' . $protocol . '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
    $out[] = 'width="' . $width . '" height="' . $height . '" id="ie_'. $obj_id .'" align="middle">';
    $out[] = '<param name="allowScriptAccess" value="sameDomain" />';
    $out[] = '<param name="movie" value="'. $base .'swf/open-flash-chart.swf?width='. $width .'&height='. $height . '&data='. $url .'" />';
    $out[] = '<param name="quality" value="high" />';
    $out[] = '<param name="bgcolor" value="#FFFFFF" />';
    $out[] = '<embed src="'. $base .'swf/open-flash-chart.swf?data=' . $url .'" quality="high" bgcolor="#FFFFFF" width="'. $width .'" height="'. $height .'" name="'. $obj_id .'" align="middle" allowScriptAccess="sameDomain" ';
    $out[] = 'type="application/x-shockwave-flash" pluginspage="' . $protocol . '://www.macromedia.com/go/getflashplayer" id="'. $obj_id .'"/>';
    $out[] = '</object>';

    if ( $use_swfobject ) {
	$out[] = '</noscript>';
    }

    return implode("\n",$out);
}
?>

3. On the controller, create a graph.php

<?php

class graph extends Controller {

	function graph() {
		parent::Controller();
	}

	function index() {
		$this->load->plugin( 'graph' );
		echo open_flash_chart_object_str( '400', '200', base_url().'graph/param/', false );

	}

	function param(){
		$this->load->library( 'opgraph' );

		$arrname = array(10,20,30,40,50);

		$this->opgraph->graph();
		$this->opgraph->bg_colour = '0xFFFFFF'; //this is a change in background
		$this->opgraph->title( 'Graph & Statistics', '{font-size: 20px; color: #736AFF}' );

		// add the data:
		$this->opgraph->set_data( $arrval );

		// we add the 3 line types and key labels
		$this->opgraph->line_hollow( 2, 4, '0xCC3399', 'Legend', 10 );

		$this->opgraph->set_x_labels( $arrname );
		$this->opgraph->set_x_label_style( 10, '0x000000', 0, 1 );

		$this->opgraph->set_y_max( 100 );
		$this->opgraph->y_label_steps( 4 );
		$this->opgraph->set_x_legend( 'Ikawka.com', 14, '#736AFF' );
		$this->opgraph->set_y_legend( 'www.ikawka.com', 14, '#736AFF' );
		echo $this->opgraph->render();
	}

} //end class

/* End of file graph.php */
/* Location: ./system/application/controllers/graph.php */

4. Run or Execute the graph/index controller, you should see the graph chart in your browser.

4 comments

  1. Does this work with version 2, sorry I dont have the time to try it now, but am curious.

    Thanks.

  2. haven’t tried version 2 yet, but i think its possible there are some few tweaks on the settings to work it out :)

  3. hahaha, you’ve copy that shit from CI forum, where i can find the graph.php class in open flash chart?

    ps : ; missing, controller line 18

Leave a Reply