]> git.bts.cx Git - cx.git/blobdiff - cx/lib/images.php
Small fixes
[cx.git] / cx / lib / images.php
index fd6d6227b5a45fdf3e5c0535181bccee20cc62cf..ea29f747938ca936df675143564bf0a03f37aba5 100644 (file)
@@ -58,11 +58,30 @@ function cx_images_get(int $limit = 0) {
        $sql .= ';';
 
        foreach (cx_db_query($sql) as $image) {
-               $p = new Image($image);
-               yield $p;
+               $i = new Image($image);
+               yield $i;
        }
 }
 
+function cx_images_find_image($image_id) {
+       $sql = 'SELECT
+               image_id,
+               image_uid,
+               image_type,
+               image_alt_text
+               FROM images
+               WHERE image_id == ?
+               OR image_uid LIKE ?
+               LIMIT 1;';
+
+       foreach (cx_db_query($sql, $image_id, $image_id . "%") as $image) {
+               $i = new Image($image);
+               return $i;
+       }
+
+       return null;
+}
+
 cx_setup_register(1, function() {
        cx_db_exec('CREATE TABLE images (
                        image_id INTEGER PRIMARY KEY,
@@ -76,5 +95,8 @@ cx_setup_register(1, function() {
                        FOREIGN KEY(image_site_id) REFERENCES sites(site_id)
                );');
 
-       mkdir(cx_user_data_path('images'), recursive: true);
+       $image_dir = cx_user_data_path('images');
+       if (is_dir($image_dir) == false) {
+               mkdir($image_dir, recursive: true);
+       }
 });