X-Git-Url: https://git.bts.cx/cx.git/blobdiff_plain/6e68608aecb6a542b9c75a13afd5002aeb7bc0f1..68d07e0d4c200b6675d8068a1b10e29bcce1e681:/cx/lib/images.php?ds=sidebyside diff --git a/cx/lib/images.php b/cx/lib/images.php index fd6d622..358a1ba 100644 --- a/cx/lib/images.php +++ b/cx/lib/images.php @@ -17,6 +17,11 @@ class Image { $this->alt_text = $dict['image_alt_text']; $this->url = $this->uid . '.' . $dict['image_type']; } + + public function get_permalink_path() { + $permalink = '/data/images/' . $this->url; + return $permalink; + } } function cx_images_add_image($site_id, $alt_text, $image_path, $image_original_filename) { @@ -58,9 +63,28 @@ 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() { @@ -76,5 +100,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); + } });