1 (edited by nakome 2012-09-06 19:52:36)

Topic: Question gallery

Hi I am trying to create a gallery and I have this data:

This would be what generates the gallery locate in admin/themes/default

<?php
class gallery {
    var $files = array();
    var $path;
    function loadFolder($path){
        $this->path = $path;
        //---Save a fix all files in directory
        $folder = opendir($this->path);
        while ($fil = readdir($folder)) {
            //---If not a dir
            if(!is_dir($fil)){
                $arr = explode('.', $fil);
                if(count($arr) > 1){
                    //---Save the names 
                    $this->files[] = $fil;
                }
            }
        }
        //---Close dir
        closedir($folder);
        //---Sort alphabetically arrangement
        sort($this->files);
    }
    function show($area = 500, $width = 100, $space = 10){
        //---Create the gallery with the names of all files
        $total = count($this->files);
        $cont = 0;
        echo '<div name="xx" style="width:'.$area.'px">';
            //---Locate the thumbnails
            for($i = 0; $i < $total; $i++){        
                echo '<div style="width:'.$width.'px; float:left; padding-right:'.$space.'px; padding-bottom:'.$space.'px;">
                        <a href="'.$this->path.'/'.$this->files[$i].'" rel="lightbox">
                            <img src="'.$this->path.'/'.$this->files[$i].'" width="'.$width.'" height="'.$width.'" />
                        </a>
                    </div>';
            }
        echo '</div>';
    }
}
?>

And this would call

<?php            
    include_once('admin/themes/default/assets/gallery.php');  // gallery file 
    $mygallery = new gallery();
    $mygallery->loadFolder('public/uploads/theme-photos'); // gallery folder
    $mygallery->show(960, 300, 10);    // 960  content   300 photos  and 10 margin 
?>

Preview

this is correct or would have serious security problems?

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

I try to update your code

Gallery class:

   class Gallery {
        public static function show($folder = '', $area = 500, $width = 100, $space = 10) {
            $files = File::scan($folder, array('jpg', 'png'));
            //---Create the gallery with the names of all files
            $total = count($files);
            $cont = 0;
            echo '<div name="xx" style="width:'.$area.'px">';
                //---Locate the thumbnails
                for($i = 0; $i < $total; $i++){        
                    echo '<div style="width:'.$width.'px; float:left; padding-right:'.$space.'px; padding-bottom:'.$space.'px;">
                            <a href="'.Option::get('siteurl').$folder.$files[$i].'" rel="lightbox">
                                <img src="'.Option::get('siteurl').$folder.$files[$i].'" width="'.$width.'" height="'.$width.'" />
                            </a>
                        </div>';
                }
            echo '</div>';
        }
    }

Usage:

<?php Gallery::show('public/uploads/', 960, 300, 10); ?>

I use File Helper and Options API here
http://monstra.org/documentation/option-api
http://monstra.org/documentation/file-helper

Monstra Loves You! Give some love back!

Re: Question gallery

good thanks and where would the file gallery.php

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

already thanks boss wink

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

Yes, you can save and include  include_once('admin/themes/default/assets/gallery.php') but it is not good practice.

You can create a plugin using Plugin API.

Just few changes and Your Gallery Plugin is ready: http://minus.com/lt64zk65f5dyL

p.s.
And Plugin easy to install http://monstra.org/documentation/plugins-installation

Monstra Loves You! Give some love back!

6 (edited by nakome 2012-09-06 21:10:30)

Re: Question gallery

Thanks I have yet to learn a lot just eight months creating websites, but I'm slowly learning English and programming before I worked in construction but the Spanish crisis has forced me to change careers

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

7 (edited by nakome 2012-09-07 18:13:15)

Re: Question gallery

as I can do to make a plugin only on page charge I call

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

>>>as I can do to only load the plugin on a page with a specific ID
this is a question ?

Monstra Loves You! Give some love back!

Re: Question gallery

I explain better sorry.
I made a plugin but is loaded on every page and I just want to be on a page charge
This is a page  preview

And This would be another page I do not want to load the plugin preview

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

Dont call <?php Gallery::show('public/uploads/', 960, 300, 10); ?> on every pages.

You can create a specific template (admin panel -> themes -> Create new template -> and add your code there) for your specific page (Edit/Create page -> Select your template).

Monstra Loves You! Give some love back!

Re: Question gallery

Yes, I did, but also load the  jquery,

This is the code:

    // Add hooks  
    Action::add('theme_header', 'Gallery::themeheaders');
    /**
     * Gallery simple class
     * put <?php Gallery::show('public/uploads/your-folder/'); ?> in your template 
     */
    class Gallery {
        /**
         * Set jquery header 
         */
        public static function themeheaders() {
                echo  ('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>');        
                echo  ('<script src="'.Option::get('siteurl').'plugins/gallery/assets/galleria-1.2.8.min.js"></script>');
                echo  ('<script>
                                Galleria.loadTheme("plugins/gallery/assets/themes/classic/galleria.classic.min.js");
                                Galleria.run("#galleria", {
                                    responsive: true,
                                    transition: "fadeslide",
                                    height:700
                                });                                 
                          </script>');    
        }
        public static function show($folder = '') {
            $files = File::scan($folder, array('jpg', 'png','gif'));
            //---Create the gallery with the names of all files
            $total = count($files);
            $cont = 0;
            echo '<div class="galleria" id="galleria">';
                //---Locate the thumbnails
                for($i = 0; $i < $total; $i++){ 
                    echo '<img src="'.Option::get('siteurl').$folder.'/'.$files[$i].'"/>';
                }
            echo '</div>';
        }
    }
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

Simple solution: delete this code from plugin

echo  ('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>'); 

Inlcude jQuery manualy on specific template

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>

p.s.
Same solution is here
http://forum.monstra.org/topic/119/star-rating/

Monstra Loves You! Give some love back!

Re: Question gallery

but the plugin will charge if you have another jquery not?

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

14 2012-09-07 19:32:35

Re: Question gallery

If you write a plugin that required a jQuery, please write in the topic note that this plugin required a jQuery.
You may have a problems if there are more then one jQuery including on the page.
Plugin dont know is jquery alredy loaded.

Monstra Loves You! Give some love back!

15 (edited by nakome 2012-09-07 19:59:12)

Re: Question gallery

test if you will understand that I speak

plugin

even not including jquery also load.

Sorry for my english.

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

  
    // If current page  "test"
    if (Uri::segment(0) == 'test') {
        echo  ('<script src="'.Option::get('siteurl').'plugins/gallery/assets/galleria-1.2.8.min.js"></script>');
    }

Action::add('theme_header', 'Gallery::themeheaders');
add everything you want to headers on all pages

I cant propouse any other solutions now. You can get a page slug that way Uri::segment(0). chech it and do some logic.

Monstra Loves You! Give some love back!

Re: Question gallery

One more proposition

<?php
    /**
     *  Gallery plugin
     *
     *  @package Monstra
     *  @subpackage Plugins
     *  @author Nakome
     *  @copyright 2012 Nakome
     *  @version 1.0.0
     *
     */
    // Register plugin
    Plugin::register( __FILE__,                    
                    __('Gallery', 'gallery'),
                    __('Gallery plugin for Monstra', 'gallery'),  
                    '1.0.0',
                    'Nakome',                 
                    'http://monstra.org/');
    /**
     * Gallery simple class
     * put <?php Gallery::show('public/uploads/your-folder/'); ?> in your template 
     */
    class Gallery {
        public static function show($folder = '') {
            echo  ('<script src="'.Option::get('siteurl').'plugins/gallery/assets/galleria-1.2.8.min.js"></script>');
            echo  ('<script>
                            Galleria.loadTheme("plugins/gallery/assets/themes/classic/galleria.classic.min.js");
                            Galleria.run("#galleria", {
                                responsive: true,
                                transition: "fadeslide",
                                height:700
                            });                                 
                      </script>');  
            $files = File::scan($folder, array('jpg', 'png','gif'));
            //---Create the gallery with the names of all files
            $total = count($files);
            $cont = 0;
            echo '<div id="galleria">';
                //---Locate the thumbnails
                for($i = 0; $i < $total; $i++){ 
                    echo '<img src="'.Option::get('siteurl').$folder.'/'.$files[$i].'"/>';
                }
            echo '</div>';
        }
    }
?>
Monstra Loves You! Give some love back!

Re: Question gallery

That's what I wanted, you're the boss

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

I update your code.
Now you can run a lot of gallery on one page.

Gallery 1 <?php Gallery::show('public/uploads1/'); ?>

Gallery 2 <?php Gallery::show('public/uploads2/'); ?>

js will be included once on page footer.

<?php
    /**
     *  Gallery plugin
     *
     *  @package Monstra
     *  @subpackage Plugins
     *  @author Nakome
     *  @copyright 2012 Nakome
     *  @version 1.0.0
     *
     */
    // Register plugin
    Plugin::register( __FILE__,                    
                    __('Gallery', 'gallery'),
                    __('Gallery plugin for Monstra', 'gallery'),  
                    '1.0.0',
                    'Nakome',                 
                    'http://monstra.org/');
    /**
     * Gallery simple class
     * put <?php Gallery::show('public/uploads/your-folder/'); ?> in your template 
     */
    class Gallery {
        public static $alredy_loaded = false;
        public static function show($folder = '') {
            if( ! Gallery::$alredy_loaded) {
                Action::add('theme_footer', 'addJS');
                function addJS() {
                    echo  ('<script src="'.Option::get('siteurl').'plugins/gallery/assets/galleria-1.2.8.min.js"></script>');
                    echo  ('<script>
                                    Galleria.loadTheme("plugins/gallery/assets/themes/classic/galleria.classic.min.js");
                                    Galleria.run(".galleria", {
                                        responsive: true,
                                        transition: "fadeslide",
                                        height:700
                                    });                                 
                              </script>');  
                }
                Gallery::$alredy_loaded = true;
            } 
            $files = File::scan($folder, array('jpg', 'png','gif'));
            //---Create the gallery with the names of all files
            $total = count($files);
            $cont = 0;
            echo '<div class="galleria">';
                //---Locate the thumbnails
                for($i = 0; $i < $total; $i++){ 
                    echo '<img src="'.Option::get('siteurl').$folder.'/'.$files[$i].'"/>';
                }
            echo '</div>';
        }
    }
?>
Monstra Loves You! Give some love back!

Re: Question gallery

yes is what I wanted

Gallery 1
Gallery 2

Now upload the plugin to share

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website