]>
git.bts.cx Git - cx.git/blob - cx/lib/images.php
   3 cx_require('lib', 'db.php'); 
   4 cx_require('lib', 'setup.php'); 
   5 cx_require('lib', 'user_data.php'); 
  14         public function __construct($dict) { 
  15                 $this->id 
= $dict['image_id']; // FIXME, hide when not used? 
  16                 $this->uid 
= $dict['image_uid']; 
  17                 $this->alt_text 
= $dict['image_alt_text']; 
  18                 $this->url 
= $this->uid 
. '.' . $dict['image_type']; 
  22 function cx_images_add_image($site_id, $alt_text, $image_path, $image_original_filename) { 
  23         $path_parts = pathinfo($image_original_filename); 
  25         $uid = hash_file("sha256", $image_path); 
  27         $target_name = $uid . "." . $path_parts['extension']; 
  28         $path = cx_user_data_path('images', $target_name); 
  30         move_uploaded_file($image_path, $path); 
  32         $creation_time = $update_time = time(); 
  34         $sql = 'INSERT INTO images ( 
  41                 VALUES (?, ?, ?, ?, ?, ?);'; 
  42         cx_db_exec($sql, $site_id, $creation_time, $update_time, $uid, $path_parts['extension'], $alt_text); 
  45 function cx_images_get(int $limit = 0) { 
  52                 ORDER BY image_creation_time DESC'; 
  55                 $sql .= ' LIMIT ' . $limit; 
  60         foreach (cx_db_query($sql) as $image) { 
  61                 $p = new Image($image); 
  66 cx_setup_register(1, function() { 
  67         cx_db_exec('CREATE TABLE images ( 
  68                         image_id INTEGER PRIMARY KEY, 
  69                         image_site_id INTEGER, 
  70                         image_creation_time INTEGER, 
  71                         image_update_time INTEGER, 
  74                         image_alt_text STRING, 
  76                         FOREIGN KEY(image_site_id) REFERENCES sites(site_id) 
  79         mkdir(cx_user_data_path('images'), recursive
: true);