static function update_overlays($task) { $errors = array(); try { $mode = $task->get('mode', 'init'); switch ($mode) { case 'init': $q = emboss::find_dirty(); foreach ($q as $item) { $ids[] = array('id' => $item->id, 'image_id' => $item->image_id, 'overlay_id' => $item->best_overlay_id); } $count = count($ids); if ($count > 0) { $task->set('ids', $ids); $task->set('count', $count); $task->set('current', 0); $task->set('mode', 'continue'); } else { $task->done = true; $task->state = 'success'; $task->percent_complete = 100; site_status::clear('emboss_dirty'); return; } break; case 'continue': $ids = $task->get('ids'); $count = $task->get('count'); $current = $task->get('current'); break; } $i = 1 * $current; $id = $ids[$i]; $current++; $task->set('current', $current); emboss_task::do_embossing($id['id'], $id['image_id'], $id['overlay_id']); if ($current >= $count) { $task->done = true; $task->state = 'success'; $task->percent_complete = 100; $task->status = 'Complete'; site_status::clear('emboss_dirty'); } else { $task->percent_complete = $current / $count * 100; $task->status = t("Reembossed {$current} of {$count} photos"); } } catch (Exception $e) { Kohana_Log::add('error', (string) $e); $task->done = true; $task->state = 'error'; $task->status = $e->getMessage(); $errors[] = (string) $e; } if ($errors) { $task->log($errors); } }
echo form::checkbox($data, 1); ?> </td> <td><?php echo $image->name; ?> </td> <td><?php echo $image->width; ?> x <?php echo $image->height; ?> </td> <td><?php echo emboss::usage_count($image->id); ?> </td> <td><?php echo html::anchor('admin/emboss/delete_overlay?name=' . $image->name . '&csrf=' . access::csrf_token(), 'delete'); ?> </td></tr> <?php } ?> <tr class="<?php echo text::alternate('g-odd', 'g-even'); ?> "><td colspan=5> <a href='javascript:checkAllOverlays()'>Check All</a> / <a href='javascript:uncheckAllOverlays()'>Uncheck All</a>
static function uninstall() { emboss::uninstall(); }
static function check_for_dirty() { $q = emboss::find_dirty(); $n = $q->count(); if ($n > 0) { $url = url::site('admin/maintenance/start/emboss_task::update_overlays?csrf=__CSRF__'); site_status::warning(t2("One of your photos needs to be (re)embossed. <a %attrs>Click here to fix it</a>", "%count of your photos need to be (re)embossed. <a %attrs>Click here to fix them</a>", $n, array('attrs' => html::mark_clean(sprintf('href="%s" class="g-dialog-link"', $url)))), 'emboss_dirty'); } else { site_status::clear('emboss_dirty'); } }
static function uninstall() { access::verify_csrf(); emboss::uninstall(); url::redirect('admin/modules'); }
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(); }