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

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 '
'; //---Locate the thumbnails for($i = 0; $i < $total; $i++){ echo ''; } echo '
'; } } ?>

And this would call

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 '
'; //---Locate the thumbnails for($i = 0; $i < $total; $i++){ echo ''; } echo '
'; } }

Usage:

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 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  in your template 
     */
    class Gallery {
        /**
         * Set jquery header 
         */
        public static function themeheaders() {
                echo  ('');        
                echo  ('');
                echo  ('');    
        }
        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 '
'; //---Locate the thumbnails for($i = 0; $i < $total; $i++){ echo ''; } echo '
'; } }
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Question gallery

Simple solution: delete this code from plugin

echo  (''); 

Inlcude jQuery manualy on specific template

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  ('');
    }

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

 in your template 
     */
    class Gallery {
        public static function show($folder = '') {
            echo  ('');
            echo  ('');  
            $files = File::scan($folder, array('jpg', 'png','gif'));
            //---Create the gallery with the names of all files
            $total = count($files);
            $cont = 0;
            echo '
'; //---Locate the thumbnails for($i = 0; $i < $total; $i++){ echo ''; } echo '
'; } } ?>
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

Gallery 2

js will be included once on page footer.

 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  ('');
                    echo  ('');  
                }
                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 '
'; //---Locate the thumbnails for($i = 0; $i < $total; $i++){ echo ''; } echo '
'; } } ?>
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