Lightroom Helper

by drswank
This is a simple helper for people who want to use the [b]lightbox.js[/b]
This is a helper for people using lightbox.js. Lightbox.js is available here: http://www.huddletogether.com/projects/lightbox2/.

There are 2 methods in this class:

$lightbox->img();
$lightbox->txt();

img() is for placing images as in a picture gallery.
txt() is for placing text links to images.

here is the code:

Helper Class:

<?php 
<?php  
class LightboxHelper extends AppHelper 
    
    var 
$tags = array(    'img'=>'<a href="%s" rel="lightbox[%s]" title="%s"><img src="%s" %s %s/></a>',
                        
'txt'=>'<a href="%s" rel="lightbox[%s]" title="%s" %s>%s</a>');

    
/**
     * @public
     * 
     * @param    $tn:String      a relative or absolute path to the thumbnail image
     * @param    $lg:String         a relative or absolute path to the large image to be shown
     * @param    $title:String     a title for the caption as well as the alt text
     * @param    $group:String    a group name if images are to be put into groups (see lightbox docs for more info)
     * @param    $tn_att:Array    an array of html attributes for the thumbnail image
     * 
     * @returns a formated <a href></a> tag
     */
    
function img($tn,$lg,$title,$group='',$tn_att=array()) {

        
$title htmlspecialchars($titleENT_QUOTES);
        return 
$this->output(sprintf($this->tags['img'], $this->_image($lg), $group$title$this->_image($tn), $this->_parseAttributes($tn_attnull''' '),' alt="'.$title.'"'));
        
    }
    
    
/**
     * @public
     * 
     * @param    $txt:String      the text for the link that goes between the <a> and the </a>
     * @param    $lg:String         a relative or absolute path to the large image to be shown
     * @param    $title:String     a title for the caption as well as the alt text
     * @param    $group:String    a group name if images are to be put into groups (see lightbox docs for more info)
     * @param    $class_att:Array an array of html attributes for the text link like "class"=>"myLBClass"
     * 
     * @returns    a formated <a href></a> tag 
     */
    
function txt($txt,$lg,$title,$group='',$class_att=array()) {

        
$title htmlspecialchars($titleENT_QUOTES);
        return 
$this->output(sprintf($this->tags['txt'], $this->_image($lg), $group$title,$this->_parseAttributes($class_attnull''' ') ,$txt));
        
    }
    
    
/**
     * @private
     * @param    $path:String    a string path to be parsed
     * @returns a url string
     */
    
function _image($path) {
        if (
strpos($path'://')||$path[0]=='/') {
            
$url $path;
        } else {
            
$url $this->webroot(IMAGES_URL $path);
        }
        return 
$url;
    }
}

?>
?>

drswank

Report

More on Helpers

Advertising

Comments

  • arjun posted on 02/16/10 07:54:36 AM
    I could see no effects when i tried this code.. It just redirected to the image without any effect.. Any solution??
    • edwinallenz posted on 04/16/10 09:06:41 AM
      I could see no effects when i tried this code.. It just redirected to the image without any effect.. Any solution??
      Are you sure, you include the scriptaculous and lightbox js files in webroot/js?

      You need to include all this

      echo $this->Html->css('lightbox');
              echo $this->Javascript->link('prototype', 'false');
              echo $this->Javascript->link('scriptaculous.js?load=effects', 'false');
              echo $this->Javascript->link('lightbox', 'false'); 
      in you layout views/layouts/default.ctp
  • denjin posted on 01/30/10 11:03:00 AM
    Having problems working out why this helper doesn't do what it's supposed to? You don't even need a helper to get lightbox to work.

    Make sure you've attached the css and javascripts in the usual way then when you make a link put this:

    View Template:


    <?php echo $html->link(__("text"true), "url", array('rel' => 'lightbox')); ?>

    You can even get it to work on images:

    View Template:


    <?php echo $html->link($html->image("image")), "url", array('rel' => 'lightbox'), nullfalse);
    ?>

    Easy
  • wernerhp posted on 01/14/10 04:09:26 AM
    I think it's a really awesome idea, but I just can't get the helper to work. It needs some refining and would be nice if you could make the whole configuration process easier. My recommendation is to add the follwoing...


        var $helpers = array('Html', 'Javascript');

        private $basePath = '/js/lightbox/';
        private $jsPath = 'js/';
        private $cssPath = 'css/';

        function init() {
            echo $this->Html->css($this->basePath . $this->cssPath . 'lightbox');
            echo $this->Javascript->link($this->basePath . $this->jsPath . 'prototype', 'false');
            echo $this->Javascript->link($this->basePath . $this->jsPath . 'scriptaculous.js?load=effects', 'false');
            echo $this->Javascript->link($this->basePath . $this->jsPath . 'lightbox', 'false');
        }


    and add $this->basePath before IMAGES_URL.

    $url = $this->webroot($this->basePath . IMAGES_URL . $path);

    Now you just have to extract lightbox to /webroot/js/lightbox and don't have to move to all the directories. finally call init().


    echo $lightbox->init();

    like i said, i couldn't get it to work. maybe it's my changes, but i doubt it. i get a thumbnail when i call

    echo $lightbox->img('/js/lightbox/images/thumb-1.jpg', '/js/lightbox/image-1.jpg', 'It works!');
    but nothing happens when i click it...
  • edwinallenz posted on 07/04/09 11:08:07 PM
    You also you need remove the background #FFFF of the A style in the cakegeneric.css file
  • gskleres posted on 07/02/09 12:00:01 AM
    Like the 2 posters above me, I don't get the lightbox effect. No errors occur, but the clicking the image or text link just redirects my browser directly to the image URL.

    My controller is "lightboxes_controller.php", as follows:

    Controller Class:

    <?php 
    <?php

    class LightboxesController extends AppController {

        var 
    $name 'Lightboxes';
        var 
    $uses = array();
        var 
    $helpers = array('Html''Javascript''Ajax''Lightbox');

        function 
    index() {
        }

    }

    ?>
    ?>

    My view is "lightboxes/index.ctp", as follows:

    View Template:



    <?php echo $lightbox->txt('Test Lightbox Image''pope.jpg''Here is my first test of lightbox'); ?>


    My layout is "layouts/default.ctp", as follows:


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title><?php echo $title_for_layout?></title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <?php echo $html->css('ieStyle'); ?>
    <?php 
    echo $scripts_for_layout ?>

    <?php 

    echo $html->css('lightbox'"stylesheet"NULLFALSE);

    echo 
    $html->charsetTag('UTF-8');
    echo 
    $javascript->link('prototype.js');
    echo 
    $javascript->link('scriptaculous.js?load=effects'); 
    echo 
    $javascript->link('lightbox.js');
    echo 
    $javascript->link('builder.js');
    ?>

    </head>
    <body>

    <?php echo $content_for_layout?>


    </body>
    </html>




    Regarding the files that come with Lightbox 2, the JS files are all in my "webroot/js/" folder, and the css file is in my "webroot/css/" folder, and all the images are in my "webroot/img/" folder. I replaced the two lines in the "lightbox.js" file as follows:


    var fileLoadingImage = "../img/loading.gif";        
    var fileBottomNavCloseImage = "../img/closelabel.gif"; 

    I also added the file "/views/helpers/lightbox.php" and copied the code at the top of this tutorial, with the exception of the redundant tags (placing only one of each instead of 2).


    I have no clue what's going wrong... can anyone help? :(
  • prod posted on 05/04/09 08:34:34 AM
    I follow the tuto too but like Jaon nothing happen... The link open the image in a blank page... someone have a solution!??
  • vanho posted on 03/30/09 03:21:04 PM
    Follow the steps in the tutorial "How I got it to work....", everything works, open the link to the images, but any effect appears, the image opens like a normal link. Someone had this kind of problem?
  • meshach posted on 01/12/09 01:41:08 PM
    Sorry for the caps. Just realized the simplicity of the problem that was driving me crazy.

    1 - As the above comment states, the builder include is crucial.
    2 - You must remember to update the path to your images folder BOTH in the lightbox.js file AND the lightbox.css file. Not sure why they don't just restructure to put the paths in one location, but for now, you need to update both.
  • nilsel posted on 07/03/08 09:40:26 AM
    Builder.js is in the lightbox-distribution, make sure you include that file too;
    or it will not work (js error; 'Builder' not declared and the likes).
    link('builder'); ?>
  • mariusvw posted on 04/21/08 09:21:30 AM
    It might happen that you need to setup your app into a directory structure (like i have for development), when you have this situation you might notice that the images in the JS are not working:


    var fileLoadingImage = "../img/loading.gif";
    var fileBottomNavCloseImage = "../img/closelabel.gif";

    You can change it to:

    var fileLoadingImage = "img/loading.gif";
    var fileBottomNavCloseImage = "img/closelabel.gif";

    I'm not 100% sure if this works in all situations but so far this works in local/live/dirs situations for me.
  • berdyk posted on 12/27/07 08:54:50 AM
    this helper not working
    the debuger gives a lots of errors
    • AYCOM posted on 01/03/08 08:26:08 PM
      Just a note that you need to be using one of the 1.2 betas for this to work since it uses AppHelper.

      1)
      Open: cake/libs/controller/pages_controller.php
      And add the helper.

      var $helpers = array('Html', 'Lightbox');

      2)
      Download lightbox and put all the .js files into your webroot/js directory, CSS file into the webroot/css directory, and all the images into the webroot/img directory.

      3)
      Download the code above (be sure to remove the extra php tags and put it into a file called lightbox.php and put that into your helper directory

      4)
      Now open the lightbox.js and change lines 65 and 66 to:

      var fileLoadingImage = "../img/loading.gif";        
      var fileBottomNavCloseImage = "../img/closelabel.gif";

      5)
      Lastly you need to link all the files so open the layout you are using and add:

      <?php echo $html->css('lightbox'); ?>
      <script type="text/javascript" src="<?php echo $this->webroot 'js/'?>prototype.js"></script>
      <script type="text/javascript" src="<?php echo $this->webroot 'js/'?>scriptaculous.js?load=effects"></script>
      <script type="text/javascript" src="<?php echo $this->webroot 'js/'?>lightbox.js"></script>

      6)
      Now in your view you can add something like:

      <?php echo $lightbox->txt('Test Lightbox Image''aycom-logo.png''Here is my first test of lightbox''A'); ?>
      <br />
      <?php echo $lightbox->txt('Another Lightbox Image''cake.power.png''Here is my second test of lightbox''A'); ?>

      I hope I didn't forget anything but let me know if I did.

      ------------------------------
      AYCOM Consulting
      http://www.aycomconsulting.com
login to post a comment.