CodeIgniter Forums
Where to put this 3rd party PHP package? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Where to put this 3rd party PHP package? (/thread-35085.html)



Where to put this 3rd party PHP package? - El Forum - 10-19-2010

[eluser]mhulse[/eluser]
Hi,

I would like to use ColorJizz in an experimental CI app, but I am not sure what is the best location to put it.

Do you think it would work best as a helper or as a library? If the latter, how would I go about making it jive with CI?

Helper seems like the easy route, but I would like to know what the pros suggest. Smile

Whatever I do, I would like to avoid modifying the 3rd party source code.

Many thanks in advance!

Cheers,
Micky


Where to put this 3rd party PHP package? - El Forum - 10-19-2010

[eluser]Watermark Studios[/eluser]
I would put it into the plugins folder. Stick the library folder in the /system/application/plugins folder. Then create a file in the plugins folder called colorjizz_pi.php.

Then you have to point that file to the library class. Something like:
Code:
<?php
require_once APPPATH.'/plugins/colorjizz/colorjizz.php';

Then you could set the plugins array of your autoload file to:
Code:
$autoload['plugin'] = array('colorjizz');

I'm not exactly sure how the ColorJizz framework is set up, but I'm sure it has a library class that allows you to access it. You should be able to extend or access your ColorJizz classes from anywhere in your CI application after this.

Thanks,

Ken


Where to put this 3rd party PHP package? - El Forum - 10-19-2010

[eluser]jdav3579[/eluser]
Or put it in libraries. I think in CI 2(when its released), they are getting rid of plugins, this way would protect it should you want to upgrade but conversions of plugins to libraries is not very hard work though!


Where to put this 3rd party PHP package? - El Forum - 10-19-2010

[eluser]Watermark Studios[/eluser]
You can load the same way too. I just looked up colorjizz and it is a single file library. I'd just stick it in the library. In that case, just name your library file something like Colorjizz.php. Put it in the /system/application/library folder. Just make sure that the class name for the file is also Colorjizz. It's just important that the filename is capitalized and the class and filename match.

Now that I'm looking at ColorJizz...it might be a bit more difficult than that. You may have to create separate files for each of the classes in the single ColorJizz file and name the files identical to the Class it represents. I'd be interested to see how this turns out.

Ken


Where to put this 3rd party PHP package? - El Forum - 10-19-2010

[eluser]mhulse[/eluser]
WOW, you folks ROCK!!!

This is great info, thanks all!

I will be experimenting with all of this later tonight and I will post back my results.

Sorry too.. I should have posted links to the source code and sample:

[url="http://code.google.com/p/colorjizz/source/browse/trunk/PHP/ColorJizz.php"]ColorJizz Source code[/url]

[url="http://code.google.com/p/colorjizz/source/browse/trunk/PHP/Samples/test.php"]Sample test page[/url]

There are also some [url="http://code.google.com/p/colorjizz/source/browse/trunk/PHP/Tests/"]test pages here[/url].

Watermark, thanks for the details... I am sure that I will be back with some more questions after I experiment. Smile

I have to say, I am pretty impressed with ColorJizz so far... It makes it pretty easy to generate a range of colors and such.

Thanks!!!!

Micky


Where to put this 3rd party PHP package? - El Forum - 10-19-2010

[eluser]mhulse[/eluser]
So, this was pretty quick and dirty, and I am about ready to head to bed, but I thought I would post my results for feedback. Smile

1. I put the ColorJizz.php library in the CI "libraries" folder.

2. I then created a new class named "Hexed" (Hexed.php) and put that in the CI "libraries" folder also.

Contents of Hexed:

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

class Hexed {
    
    function __construct()
    {
        
        require_once('ColorJizz.php');
        
    }
    
    public function jizzed($val)
    {
        
        return new Hex($val);
        
    }
    
}

In my (default, out of the box) controller, I have this:

Code:
<?php

class Welcome extends Controller {
    
    private $data;
    
    function Welcome()
    {
        parent::Controller();
        
        $this->load->library('hexed');
        
    }
    
    function index()
    {
        
        
        $white = $this->hexed->jizzed(0xffffff);
        $black = $this->hexed->jizzed(0x000000);
        $blue = $this->hexed->jizzed(0x2491B5);
        
        /* ....snip.... */
        
    }
}

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

That appears to work!

I would definitely be interested in hearing how I can improve the code. Thoughts?

Thank you!!!

Cheers,
Micky


Where to put this 3rd party PHP package? - El Forum - 10-20-2010

[eluser]Mikeemoo[/eluser]
Isn't Google analytics great?

I haven't paid tooo much attention to the PHP version of ColorJizz. If you see any bugs, or notice anything that can be improved, please feel free to either submit a patch or let me know of the bug and I'll fix it.

There's a few things in the library that are poorly ported.

Enjoy Smile


Where to put this 3rd party PHP package? - El Forum - 10-20-2010

[eluser]mhulse[/eluser]
[quote author="Mikeemoo" date="1287583623"]Isn't Google analytics great?

I haven't paid tooo much attention to the PHP version of ColorJizz. If you see any bugs, or notice anything that can be improved, please feel free to either submit a patch or let me know of the bug and I'll fix it.

There's a few things in the library that are poorly ported.

Enjoy Smile[/quote]

Heeeeeeey! Wow, thanks for replying! Smile

I am loving your code. I have not noticed any bugs so far, but then again, I am definitely not as advanced with my PHP skillz as you are. If I do notice anything I will let you know. Smile

Actually, I do have a quick question... What method would I use to return a hex value (#999999, for example)? I can return the RGB values easily, but I have yet to discover a method that will convert the RGB to a hex value.

Like I said before, I am loving ColorJizz! The range() method is awesome! Smile

Cheers!
Micky


Where to put this 3rd party PHP package? - El Forum - 10-20-2010

[eluser]Mikeemoo[/eluser]
Hi,

Just convert it to a Hex, then use toString() to get it as a string representation.

For example:

Code:
echo new RGB(255, 0, 0)->toHex()->toString(); // prints "FF0000"
echo new Hex(0x00FF00)->toString(); // prints "00FF00"
echo new Hex::fromString("#0000FF")->toString(); // prints "0000FF"
echo new Hex(0xFF0000)->toRGB()->toString(); // prints 255,0,0

// draw 10 colors ranging from green to red..
foreach (new RGB(0, 255, 0)->range(new Hex(0xFF0000), 10) as $color){
  echo $color->toHex()->toString();
}

You can string as many conversions together as you like and it should still work (although it'd be mostly pointless..)

For example:

Code:
echo new Hex(0xFF0000)->toCIELab()->toCIELCh()->toRGB()->toCMYK()->toHex()->toString(); // hopefully comes out as FF0000!

Every color format has a "to" method that will convert to any other color format.


Where to put this 3rd party PHP package? - El Forum - 10-20-2010

[eluser]mhulse[/eluser]
[quote author="Mikeemoo" date="1287617715"]Hi,

Just convert it to a Hex, then use toString() to get it as a string representation.

...<snip>...

Every color format has a "to" method that will convert to any other color format.[/quote]

WOW, that is sooooo cool! Thanks so much for the examples, that will really help me get the ball rolling.

I had not used the toString() method yet... I had been iterating through the returned array. For example:

Code:
&lt;?php
//...
$black = new Hex(0x000000);
$blue = new Hex(0x2491B5);
$range2 = $blue->range($black, 10, TRUE);
//...
?&gt;

&lt;?php foreach ($range2 as $key => $val): ?&gt;
    
    <div style="width:50px;height:50px;float:left;display:inline;background-color:rgb(&lt;?=$val->toRGB()->r?&gt;, &lt;?=$val->toRGB()->g?&gt;, &lt;?=$val->toRGB()->b?&gt;)"></div>
    
&lt;?php endforeach; ?&gt;

Well, the above works great, but it looks like the toString() method could save me some work. Smile

I love this code!!!!!

Thanks so much Mike! I really appreciate it. Smile