WebsiteBaker Support (2.13.x) > Modules

New photoalbum module

(1/4) > >>

netraam:
Hello everyone,

I've made a new photo album module. I needed a simple photoalbum that show's the photo's in a folder an also in it's subfolders. The extisting photo albums that also track the photo's in the subfolders where to extensive for my purpose. So after many years of using WebsiteBaker i've give it a try to write my first module.
Those who are interested in it can find it on github: https://github.com/nethraam/pixofcake
You can find some screenshots in the repository. I thought I would be nice to share this here. 

The module works, but i know there is room for improvement and probably there are still some errors in it, your feedback is welcome.

sternchen8875:
Hi and Thanks for the job!!  (Y)

some rules...

* use language files, at minimum in englisch and german, possible in all 23 installed languages from WB
* your image folder must be the media-folder or a subfolder from MediaDirectory. Better as a free input field is a select box with this folders (see example in attachement)
* use a default value for both checkboxes in save.php. Use if(isset...) to read a submitted value, if not submitted, use the default value
* its better, to use integer fields for the checkbox values (0 or 1) or enum(), go'es faster and better to code
* prevent your install-struct.sql.php with a php-code in the top
Some errors from the test
Undefined array key "crop_images" - if you dont submitted a value for this
Undefined array key "show_filenames" - if you dont submitted a value for this
dispatch\find_photos "foreach() argument must be of type array|object, false given - if you dont submit a existed folder

code, to prevent the install-struct.sql.php (see also in the Accordion-Module)

--- Quote ----- <?php header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); echo '404 Not Found'; flush(); exit;?>
--- End quote ---

function, to read all subfolders from /media


--- Quote ---function MediaDirectoryList($directory, $show_hidden = false){
    $aMediaFolderList = [];
    if (\is_dir($directory))
    {
        $dir = array_values(array_diff(\scandir($directory),['.','..'])); //Open directory
        foreach ($dir as $key => $entry) {
            if(($entry[0] === '.') && ($show_hidden == false)) { continue; } // Skip hidden files
            $sItem = str_replace('//', '/',$directory.'/'.$entry.(\is_dir($directory.'/'.$entry) ? '' : ''));
            if (\is_dir($sItem)) { // Add dir and contents to list
                $aMediaFolderList = \array_merge($aMediaFolderList, MediaDirectoryList($sItem));
                $aMediaFolderList[] = str_replace(WB_PATH."/",'',$sItem);
            }
        }
    }
    if (\natcasesort($aMediaFolderList)) {
        // new indexing
        $aMediaFolderList = \array_merge($aMediaFolderList);
    }
    return $aMediaFolderList; // Now return the list
}
$aMediaFolderList = MediaDirectoryList(WB_PATH.MEDIA_DIREC TORY);
--- End quote ---

Result is a array, called $aMediaFolderList

use it for example like this


--- Quote ---<select name="url" style="width: 100%;padding:4px;">
                <option value="media">media</option>
                <?php
                foreach ($aMediaFolderList as $aFolder){
                    echo '<option value="'.$aFolder.'" ';
                    if ($aFolder == $url){echo ' selected = "selected"';}
                    echo ' > '.$aFolder.'</option>';
                }
                ?>     
            </select>
--- End quote ---

example for the default value in save.php for non-submitted fields


--- Quote ---// crop_images / default=''
        if(isset($aRequestVars['crop_images']) && ($aRequestVars['crop_images'] == 'checked')) {
            $sCropImages = 'checked';
        }else{
            $sCropImages = '';
        }
--- End quote ---

proof the incoming datas also for the correct data-type, means integers with is_numeric()

some example links from our addons

- Brax Highslide Gallery B -> repaired in last week, show the old module structure, you can use it as example for the language files && inclusion

- Accordion -> show the new module structure "for the future", from my personal view easyer to handle, but its new. Has a included Twig-Template-Editor and this give the possibility, to use in every output section a different template

Please ask, if you need help

dbs:
For more feedback maybe it is a good idea to attache the module here as installable module.
Or give github now installable zips?

sternchen8875:

--- Quote from: dbs on February 09, 2025, 09:43:42 PM ---For more feedback maybe it is a good idea to attache the module here as installable module.
Or give github now installable zips?

--- End quote ---


i add the module in the attachement (ZIP-Date: 09.02.2025, 14:24

Github use a special structure, good for developement, but not for the direct install as WB-module



dbs:
First problem in the install procedure.
The install-struct.sql.php contains this lines:

--- Code: ---DROP TABLE IF EXISTS `{TABLE_PREFIX}mod_pixofcake`;
CREATE TABLE IF NOT EXISTS `wb_mod_pixofcake` (
--- End code ---

the first line is right. the second, with hardcoded table prefix, will not work in many cases.

The module works once you have figured out how to specify the URL It is not https://... and not media/myfolder. Must be /media/myfolder.
A hint as to what the URL should look like would be nice

Navigation

[0] Message Index

[#] Next page

Go to full version