• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

minigallery - imgur style

tightwork

Chevereto Member
Hi,

I would like a small mini gallery on the index page, like imgur. I first tried with a simple RecursiveDirectoryIterator although I don't get the viewer page this way. I realized I can utilize the FileList class and easily get image_url and image_viewer. Is this a json object? What is the best way to access this?

I tried to:
$filelist = new Filelist('all','desc', 20);

print_r($filelist);

::returns array data::


Problem is when I want to loop through it and build a image grid, the dirty hacks are because I want to use relative dir.

* Why is this anyway? I think it is odd the domain is in the database for each image vs set a $config['domain'] and join/implode where needed? (ugh where is a php ORM?!)

foreach($filelist as $key) {
$path = explode("com", $key['image_url']); // dirty hack
$thumb = explode("com", $key['image_thumb_url']); // another dirty hack
?><a href="<? echo $path[1]; ?>"><img src="<? echo $thumb[1];?>"> </a><?
}


This works but there are empty imgs because They whole array beings with:
[error] =>
[ok] =>

I suppose I would need a for loop and start to iterate from index to length.

OR

Is there any better way to get this data or am I on the right track?

Is there anyway to utilize the admin gallery? Would be nice if that could be re factored to be more generic since overall it should be json and could use all the dozens of jquery galleries around.

Maybe that's just it! How could I json this? Just encode $filelist?

Thank you,
Bryan
 
Not even the folders or the image url or anything like that is on the db. When you call the Filelist class you get a populated array with shorthands like image url, thumb url, etc. So you can easily get the needed values without additional code and none of this values is fetched directly form the db, this values are being populated on the Filelist class.

If you need relative paths from a URL you can do it in a quick and easy way:
PHP:
function url_to_relative($url) {
    return str_replace(__CHV_BASE_URL__, __CHV_RELATIVE_ROOT__, $url);
}

Then, you can do a array_map, include the result in a foreach loop, etc.

In 2.4 there will be the introduction of the Chevereto loop for the uploaded images (uploaded.php) and in the future, this Chevereto loop will be extended to be used to retrieve custom image objects with custom queries. At this moment you should stick with the Filelist class and populate this functions on the function.php file of your custom theme. Then you can call it on your themes using my_own_function() and so on.

You will soon notice that if you can populate and declare the $images array, it will hooked to the Chevereto loop and you will be able to iterate in a template file, just like wordpress (while have_post() etc)

The Chevereto loop (2.4) looks like this:
PHP:
function have_images() {
    global $images, $imageloop;
    if(!check_value($images)) {
        if(is_uploaded()) {
            $images = get_uploaded_images();
        } else {
            return false;
        }
    }
    return ($imageloop + 1 < count($images) ? true : false);
}
function the_image() {
    global $images, $image, $imageloop;
    $image = $images[$imageloop+1];
    $imageloop++;
}

Problem is that the results of the Filelist class is not the same as the $images array handled by the loop, the array is way different. So until I update the Filelist class I'm afraid that you can't use directly the loop.

By the way, since you point up this.. I've added (on 2.4) all this functions to convert absolute paths, relative paths and Chevereto URLs:
PHP:
/**
* relative_to_absolute
* Converts relative path to absolute path
*/
function relative_to_absolute($filepath) {
    return str_replace(__CHV_RELATIVE_ROOT__, __CHV_ROOT_DIR__, str_replace('\\', '/', $filepath));
}
 
/**
* relative_to_url
* Converts relative path to url
*/
function relative_to_url($filepath) {
    return str_replace(__CHV_RELATIVE_ROOT__, __CHV_BASE_URL__, str_replace('\\', '/', $filepath));
}
 
/**
* absolute_to_relative
* Converts absolute path to relative path
*/
function absolute_to_relative($filepath) {
    return str_replace(__CHV_ROOT_DIR__, __CHV_RELATIVE_ROOT__, str_replace('\\', '/', $filepath));
}
 
/**
* absolute_to_url
* Converts absolute path to URL
*/
function absolute_to_url($filepath) {
    return str_replace(__CHV_ROOT_DIR__, __CHV_BASE_URL__, str_replace('\\', '/', $filepath));
}
 
/**
* url_to_relative
* Converts full chevereto URL to relative path
*/
function url_to_relative($url) {
    return str_replace(__CHV_BASE_URL__, __CHV_RELATIVE_ROOT__, $url);
}
 
/**
* url_to_absolute
* Converts full chevereto URL to absolute path
*/
function url_to_absolute($url) {
    return str_replace(__CHV_BASE_URL__, __CHV_ROOT_DIR__, $url);
}
 
Back
Top