static function evaluate_overlays() { $overlays = ORM::factory('emboss_overlay')->where('active', '=', 1)->find_all(); $images = ORM::factory('item')->where('type', '=', 'photo')->find_all(); $n_new = 0; $n_update = 0; $n_none = 0; $has_changes = 0; foreach ($images as $image) { $overlay_id = emboss::determine_best_overlay($image, $overlays); if ($overlay_id < 0) { $n_none++; } $q = ORM::factory('emboss_mapping')->where('image_id', '=', $image->id)->find(); if (!$q->loaded()) { if ($overlay_id > 0) { $n_new++; } $q->image_id = $image->id; $q->best_overlay_id = $overlay_id; $q->cur_overlay_id = -1; $q->cur_gravity = 'unset'; $q->cur_transparency = -1; $q->save(); } else { if ($q->best_overlay_id != $overlay_id) { if ($overlay_id > 0) { $n_update++; } $q->best_overlay_id = $overlay_id; $q->save(); } } } if ($n_none) { emboss::info('Cannot find an overlay for ' . $n_none . t2(' image', ' images')); } if ($n_new) { emboss::info($n_new . t2(' image needs', ' images need', $n_new) . ' now have an overlay available'); } if ($n_update) { emboss::info(t2('This changes the overlay for 1 image', "This changes the overlay for {$n_update} images", $n_update)); } if ($n_none || $n_new || $n_update) { } else { message::info('All photos are being embossed with the correct overlay'); } }
static function item_created($item) { if (!$item->is_photo()) { return; } $path = $item->file_path(); $dirs = explode('/', $path); array_pop($dirs); $dir = implode('/', $dirs); $orig = str_replace(VARPATH . 'albums/', VARPATH . 'originals/', $path); $origdir = str_replace(VARPATH . 'albums/', VARPATH . 'originals/', $dir); emboss::mkdir_recursive($origdir); @copy($path, $orig); $q = ORM::factory('emboss_mapping'); $q->image_id = $item->id; $q->best_overlay_id = emboss::determine_best_overlay($item); $q->cur_overlay_id = -1; $q->cur_gravity = ''; $q->cur_transparency = -1; $q->save(); emboss::check_for_dirty(); }