From 03af14df9f41f036e1283d8ebaa89e7cc545ec60 Mon Sep 17 00:00:00 2001 From: Quentin Albrand Date: Thu, 1 Mar 2012 19:10:38 +0100 Subject: [PATCH] #1460356 - comment 5671144 : Image module is now optional. If not enabled the user will be able to upload images for background but not re-use them. --- .../sweaver_plugin_editor.inc | 43 ++++++++++--------- .../sweaver_plugin_styles.inc | 2 + sweaver.inc | 12 +++++ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/plugins/sweaver_plugin_editor/sweaver_plugin_editor.inc b/plugins/sweaver_plugin_editor/sweaver_plugin_editor.inc index ecce2ab..bbe14ab 100644 --- a/plugins/sweaver_plugin_editor/sweaver_plugin_editor.inc +++ b/plugins/sweaver_plugin_editor/sweaver_plugin_editor.inc @@ -483,26 +483,29 @@ class sweaver_plugin_editor extends sweaver_plugin { break; case 'image': - return array( - '#type' => 'managed_file', - '#title' => $property->description, - '#size' => '40', - '#upload_location' => file_default_scheme() . '://sweaver/', - '#upload_validators' => array( - 'file_validate_is_image' => array(), - 'file_validate_extensions' => array('png gif jpg jpeg'), - ), - ); - - - //return array( -// '#type' => 'select', -// '#title' => $property->description, -// '#options' => $images, -// '#attributes' => array( -// 'class' => array('background-image'), -// ), -// ); + $sweaver = Sweaver::get_instance(); + if ($sweaver->is_plugin_activated('sweaver_plugin_images')){ + return array( + '#type' => 'select', + '#title' => $property->description, + '#options' => $images, + '#attributes' => array( + 'class' => array('background-image'), + ), + ); + } + else { + return array( + '#type' => 'managed_file', + '#title' => $property->description, + '#size' => '40', + '#upload_location' => file_default_scheme() . '://sweaver/', + '#upload_validators' => array( + 'file_validate_is_image' => array(), + 'file_validate_extensions' => array('png gif jpg jpeg'), + ), + ); + } break; case 'select': diff --git a/plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc b/plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc index 7df7670..e41e941 100644 --- a/plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc +++ b/plugins/sweaver_plugin_styles/sweaver_plugin_styles.inc @@ -637,7 +637,9 @@ class sweaver_plugin_styles extends sweaver_plugin { if ($fid > 0){ $file = file_load($fid); $file->status = FILE_STATUS_PERMANENT; + $file->description = $file->filename; file_save($file); + drupal_write_record('sweaver_image', $file); } } diff --git a/sweaver.inc b/sweaver.inc index a6a9c7f..3e3cb69 100644 --- a/sweaver.inc +++ b/sweaver.inc @@ -102,6 +102,18 @@ class Sweaver { private function add_plugin(Sweaver_plugin $plugin) { $this->plugins[] = $plugin; } + + /** + * is_plugin_activated + * Check if a plugin is activated + * @return true if activated + */ + public function is_plugin_activated($name) { + if ($this->plugins[$name]) { + return isset($this->plugins_registry_enabled[$name]); + } + return false; + } /** * get_plugin. -- 1.7.7.1.msysgit.0