Part of the EllisLab Network
   
3 of 12
3
Carabiner 1.4: Asset Management Library
Posted: 22 June 2009 10:04 AM   [ Ignore ]   [ # 21 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  04-27-2007

hi

i tried to use u’r lib but i have some problems

i use ci on windows using wamp

so i have c:\wamp\www as web folder

i made a alias so now my app is installed like this

c:\wamp\app\ with url http://localhost/app/

and it works ok

i took out the application folder from system
and moved system out of app folder and changed in index.php $system_folder = “../system”;

so now i have

c:\wamp\system
c:\wamp\app\application
c:\wamp\app\cache
c:\wamp\app\js
c:\wamp\app\css

in my .htaccess i have

Options +FollowSymLinks
Options
-Indexes
DirectoryIndex index
.php
RewriteEngine on
RewriteBase
/app/
RewriteCond $1 !^(index\.php|imagini|css|js|cache|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ index.php?/$1 [L,QSA]

in carabiner conf i have folders defined like this $config[‘cache_dir’] = ‘cache/’;

when i load a js it tries to write it to C:\wamp\cache\ but it should be c:\wamp\app\cache\

any sugestion ?

Profile
 
 
Posted: 22 June 2009 12:26 PM   [ Ignore ]   [ # 22 ]  
Summer Student
Total Posts:  14
Joined  03-14-2009

I think I have Amazon S3/CDN integration with Caribinner working pretty well now. Here are the steps I took:

1. Add an S3 library to your application/libraries folder. I used the one available here: http://undesigned.org.za/2007/10/22/amazon-s3-php-class and then customized it so that it pulled the variables from my config file. The only thing I changed in the S3.php file (which is the one to add to application/libraries) was the __construct on line 57 so that it looked like this:

public function __construct($accessKey = null, $secretKey = null, $useSSL = true) {
      
//Start Customizations
      
$this->CI = get_instance();
    
$accessKey = $this->CI->config->item('key_id');
    
$secretKey = $this->CI->config->item('secret_key');
    
//End Customizations
        
if ($accessKey !== null && $secretKey !== null)
            
self::setAuth($accessKey, $secretKey);
        
self::$useSSL = $useSSL;
    
}

2. Next, update the carabiner config file with the following variables

$config['key_id'] = 'XXXXXXXX'; //Your Amazon key_id
$config['secret_key'] = 'XXXXX'; //Your Amazon secret_key
$config['cdn_bucket'] = 'yourcdnbucket'; //The bucket that will act as your CDN
$config['use_cdn'] = TRUE; //Enabling the CDN functions in carabiner
$config['cdn_url'] = 'http://cdn.example.com/'; //The URL used to access your CDN

3. Finally, modify the carabiner library in two spots:
The _cache function should look like this:

private function _cache($filename, $file_data)
    
{

        $filepath
= $this->cache_path . $filename;
        
$success = file_put_contents( $filepath, $file_data );

        if(
$success) :
            
log_message('debug', 'Carabiner: Cache file '.$filename.' was written to '.$this->cache_path);
      
      if(
$this->CI->config->item('use_cdn') == TRUE)
      
{
        
//If it's a production environment, move the file to the Amazon S3 CDN bucket
        
if($this->dev == FALSE)
        
{
          $this
->CI->load->library('S3');
          
$this->CI->s3->putObjectFile($filepath, $this->CI->config->item('cdn_bucket'), $this->cache_dir.$filename, S3::ACL_PUBLIC_READ);
        
}
      }

      
            
return TRUE;
        else :
            
log_message('error', 'Carabiner: There was an error writing cache file '.$filename.' to '.$this->cache_path);
            return
FALSE;
        endif;
    
}

The _tag function should look like this:

private function _tag($flag, $ref, $cache = FALSE, $media = 'screen')
    
{

        
switch($flag){
        
            
case 'css':
                
                
$dir = ( $this->isURL($ref) ) ? '' : ( ($cache) ? $this->cache_uri : $this->style_uri );
        
        if(
$this->CI->config->item('use_cdn') === TRUE && $this->dev == FALSE)
        
{
          $dir
= $this->CI->config->item('cdn_url').$this->cache_dir;
        
}
                
                
return '<link type="text/css" rel="stylesheet" href="'.$dir.$ref.'" media="'.$media.'" />'."\r\n";
            
            break;

            case
'js':
                
                
$dir = ( $this->isURL($ref) ) ? '' : ( ($cache) ? $this->cache_uri : $this->script_uri );
                
        if(
$this->CI->config->item('use_cdn') === TRUE && $this->dev == FALSE)
        
{
          $dir
= $this->CI->config->item('cdn_url').$this->cache_dir;
        
}
        
                
return '[removed]CI->config->item('charset').'">[removed]'."\r\n";
            
            break;
        
        }
    
    }

That should be it. Now when you are in a production environment, anytime a new cache file is created it will automatically be loaded into Amazon S3, which can act as a CDN. Then, on the site, the files use the CDN domain instead of the normal domain. Let me know if you have suggestions on how to improve this.

Profile
 
 
Posted: 24 June 2009 07:59 AM   [ Ignore ]   [ # 23 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  04-27-2007

solved my problem i modified the lib changed dirname(FCPATH) to just FCPATH

Profile
 
 
Posted: 25 June 2009 06:31 AM   [ Ignore ]   [ # 24 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  104
Joined  01-21-2009

@quasiperfect I’m glad you got it to work.

@topherdan1 That looks like a really solid solution!  There are a few things you could change to make the code a little simpler:

First, you can just do

if($this->use_cdn && !$this->dev)

instead of

if($this->CI->config->item('use_cdn') === TRUE && $this->dev == FALSE)

That’s because the config function is lazy, and will drink up whatever items are in the config file (or array) and make them class variables. That also applies to anyplace you use this syntax:

$this->CI->config->item('')

The only other thing I would do is adjust the logging in the cache function, so it looks something like this:

private function _cache($filename, $file_data)
    
{
        $filepath
= $this->cache_path . $filename;
        
$success = file_put_contents( $filepath, $file_data );

        if(
$success) :
            
log_message('debug', 'Carabiner: Cache file '.$filename.' was written to '.$this->cache_path);
      
            if(
$this->use_cdn == TRUE && $this->dev == FALSE):

                
$this->CI->load->library('S3');
                
$cdn = $this->CI->s3->putObjectFile($filepath, $this->cdn_bucket, $this->cache_dir.$filename, S3::ACL_PUBLIC_READ);
                
                if(
$cdn){
                    log_message
('debug', 'Carabiner: Cache file '.$filename.' was written to the CDN bucket '.$this->cdn_bucket);
                    return
TRUE;
                
}else{
                    log_message
('error', 'Carabiner: There was an error writing cache file '.$filename.' to  the CDN bucket '.$this->cdn_bucket);
                    return
FALSE;
                
}
    
            
endif;
      
            return
TRUE;
        else :
            
log_message('error', 'Carabiner: There was an error writing cache file '.$filename.' to '.$this->cache_path);
            return
FALSE;
        endif;
    
}

These are all minor things, though.

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

Profile
 
 
Posted: 25 June 2009 09:44 PM   [ Ignore ]   [ # 25 ]  
Grad Student
Avatar
Rank
Total Posts:  87
Joined  07-07-2008

Just want to say great job on this lib. I’ve been toying around with building a library with the same basic functionality but this is working great for me so far (it’s been an hour raspberry )

I only have 2 comments :

1) integration with tinyMCE seems sticky, i got it to work finally but i have it linking to the tiny_mce.js separately. I might be doing something else wrong, but i’ll have to look in further.

2) if you could, allow for a return value on the display function, ie

$script_tag = $this->carabiner->display('js', TRUE);  // return as string
$this->head->add_line($script_tag);

i build my page head through output buffering so the echo doesn’t matter, but i think its more CI-view-esque to have that option.

thx again!

CC

Profile
 
 
Posted: 26 June 2009 10:12 AM   [ Ignore ]   [ # 26 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  104
Joined  01-21-2009

Thanks!  I’m glad it’s working for you.

1) I’ve had issues with other Rich Text Editors as well.  Flagging the file(s) to not be combined (or minified, frankly) should solve the problem.  Of course, this is less than ideal, but there’s sufficient complexity in those tools that I’ve been willing to accept the trade-off between my time trying to troubleshoot and the extra few kb and http request.

2) That’s an interesting idea.  I’ll keep it mind. In the short term, output buffering is the perfect solution.

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

Profile
 
 
Posted: 04 July 2009 05:48 AM   [ Ignore ]   [ # 27 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  04-27-2007

+1 for “if you could, allow for a return value on the display function”

Profile
 
 
Posted: 13 July 2009 11:21 PM   [ Ignore ]   [ # 28 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  117
Joined  05-03-2008

Hi Tony,

Great application and extension of these different libraries in such an efficient manner. I have gotten the library to work but I am wondering how one would go about dynamically adding a js file to the head of site, based on the controller/method being called?

I tried exploring the new “groups” feature but this only seemed to add my new js file at the top of the other js files. In turn this seemed to break my site?

 Signature 

Reality Knights - Have more fun
Play over 7000+ Free Games

Profile
 
 
Posted: 13 July 2009 11:35 PM   [ Ignore ]   [ # 29 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  104
Joined  01-21-2009

@dnyce I’m glad you like it.

Adding scripts to the head of your site is as easy as calling

$this->carabiner->display();

in your view.

If that doesn’t help, feel free to provide some code examples of what you’re trying to do.  You can post it here, or message me directly.

Good Luck!

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.

Profile
 
 
Posted: 13 July 2009 11:49 PM   [ Ignore ]   [ # 30 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  117
Joined  05-03-2008

No,

Actually the issue I was having was with the dynamic calling of files within a group, but once I played with it some more, I managed to resolve the issue on my own.

Great Library again!

:D

 Signature 

Reality Knights - Have more fun
Play over 7000+ Free Games

Profile
 
 
   
3 of 12
3
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 10:15 AM
Total Registered Members: 119469 Total Logged-in Users: 24
Total Topics: 125732 Total Anonymous Users: 1
Total Replies: 661658 Total Guests: 366
Total Posts: 787390    
Members ( View Memberlist )