static function deactivate()
 {
     // ensure that update modes are disabled
     image_optimizer::deactivate_update_mode("thumb");
     image_optimizer::deactivate_update_mode("resize");
     // remove graphics rules
     image_optimizer::remove_image_optimizer_rule("thumb");
     image_optimizer::remove_image_optimizer_rule("resize");
 }
 public function save()
 {
     access::verify_csrf();
     $form = $this->_get_admin_form();
     if ($form->validate()) {
         foreach (array('jpg', 'png', 'gif') as $type) {
             module::set_var("image_optimizer", "path_" . $type, $form->paths->{"path_" . $type}->value);
             module::set_var("image_optimizer", "optlevel_thumb_" . $type, $form->thumb->{"optlevel_thumb_" . $type}->value);
             module::set_var("image_optimizer", "optlevel_resize_" . $type, $form->resize->{"optlevel_resize_" . $type}->value);
         }
         module::set_var("image_optimizer", "rotate_jpg", $form->rotate->rotate_jpg->value == 1);
         foreach (array('thumb', 'resize') as $target) {
             module::set_var("image_optimizer", "convert_" . $target . "_gif", $form->{$target}->{"convert_" . $target . "_gif"}->value);
             module::set_var("image_optimizer", "convert_" . $target . "_png", $form->{$target}->{"convert_" . $target . "_png"}->value);
             module::set_var("image_optimizer", "metastrip_" . $target, $form->{$target}->{"metastrip_" . $target}->value == 1);
             module::set_var("image_optimizer", "progressive_" . $target, $form->{$target}->{"progressive_" . $target}->value == 1);
             // deal with enable changes
             $enable_old = module::get_var("image_optimizer", "enable_" . $target);
             $enable_new = $form->{$target}->{"enable_" . $target}->value == 1;
             if ($enable_new && !$enable_old) {
                 image_optimizer::add_image_optimizer_rule($target);
                 module::set_var("image_optimizer", "enable_" . $target, true);
             } elseif (!$enable_new && $enable_old) {
                 image_optimizer::remove_image_optimizer_rule($target);
                 module::set_var("image_optimizer", "enable_" . $target, false);
             }
             // deal with update mode changes
             $update_mode_old = module::get_var("image_optimizer", "update_mode_" . $target);
             $update_mode_new = $form->{$target}->{"update_mode_" . $target}->value == 1;
             if ($update_mode_new && !$update_mode_old) {
                 image_optimizer::activate_update_mode($target);
             } elseif (!$update_mode_new && $update_mode_old) {
                 image_optimizer::deactivate_update_mode($target);
             }
             // dirty images if needed
             if ($form->{$target}->{"rebuild_" . $target}->value == 1) {
                 image_optimizer::dirty($target);
             }
         }
         // all done; redirect with message
         message::success(t("Image optimizer settings updated successfully"));
         url::redirect("admin/image_optimizer");
     }
     // not valid - print screen from existing form
     $this->_print_screen($form);
 }
 static function add_image_optimizer_rule($target)
 {
     // to prevent duplicates, remove any existing instances first
     image_optimizer::remove_image_optimizer_rule($target);
     // then add the new one
     $rule = ORM::factory("graphics_rule");
     $rule->module_name = "image_optimizer";
     $rule->target = $target;
     $rule->operation = 'image_optimizer::optimize';
     $rule->priority = 999999999;
     // this MUST be larger than all others to be last
     $rule->args = serialize($target);
     // this isn't typical for other graphics rules
     $rule->active = true;
     $rule->save();
 }