diff --git a/main/inc/lib/plugin.class.php b/main/inc/lib/plugin.class.php new file mode 100644 index 0000000000..3c32bb04b2 --- /dev/null +++ b/main/inc/lib/plugin.class.php @@ -0,0 +1,176 @@ + + */ +class Plugin +{ + + protected $version = ''; + protected $author = ''; + protected $fields = array(); + + protected function __construct($version, $author, $settings = array()) + { + $this->version = $version; + $this->author = $author; + $this->fields = $settings; + + global $language_files; + $language_files[] = 'plugin_' . $this->get_name(); + } + + function get_info() + { + $result = array(); + + $result['title'] = $this->get_title(); + $result['comment'] = $this->get_comment(); + $result['version'] = $this->get_version(); + $result['author'] = $this->get_author(); + if ($form = $this->get_settings_form()) + { + $result['settings_form'] = $form; + foreach ($this->fields as $name => $type) + { + $value = $this->get($name); + $result[$name] = $value; + } + } + return $result; + } + + function get_name() + { + $result = get_class($this); + $result = str_replace('Plugin', '', $result); + $result = strtolower($result); + return $result; + } + + function get_title() + { + return $this->get_lang('plugin_title'); + } + + function get_comment() + { + return $this->get_lang('plugin_comment'); + } + + function get_version() + { + return $this->version; + } + + function get_author() + { + return $this->author; + } + + function get_css() + { + $name = $this->get_name(); + $root = api_get_path(SYS_PLUGIN_PATH); + $path = "$root/$name/resources/$name.css"; + if (!is_readable($path)) + { + return ''; + } + $css = array(); + $css[] = file_get_contents($path); + $result = implode($css); + return $result; + } + + /** + * + * @return FormValidator + */ + function get_settings_form() + { + $result = new FormValidator($this->get_name()); + + $defaults = array(); + foreach ($this->fields as $name => $type) + { + $value = $this->get($name); + $defaults[$name] = $value; + $type = $type ? $type : 'text'; + if ($type == 'wysiwyg') + { + $result->add_html_editor($name, $this->get_lang($name)); + } + else + { + $result->addElement($type, $name, $this->get_lang($name)); + } + } + $result->setDefaults($defaults); + + $result->addElement('style_submit_button', 'submit_button', $this->get_lang('Save')); + return $result; + } + + function get($name) + { + $content = ''; + $title = 'Static'; + $settings = $this->get_settings(); + foreach ($settings as $setting) + { + if ($setting['variable'] == ($this->get_name() . '_' . $name)) + { + return $setting['selected_value']; + } + } + + return false; + } + + private $settings = null; + + public function get_settings() + { + if (is_null($this->settings)) + { + $settings = api_get_settings_params(array("subkey = ? AND category = ? AND type = ? " => array($this->get_name(), 'Plugins', 'setting'))); + $this->settings = $settings; + } + return $this->settings; + } + + private $strings = null; + + public function get_lang($name) + { + if (is_null($this->strings)) + { + global $language_interface; + + $root = api_get_path(SYS_PLUGIN_PATH); + $name = $this->get_name(); + $language = $language_interface; + $path = "$root/$name/lang/$language.php"; + if (is_readable($path)) + { + include $path; + $this->strings = $strings; + } + else + { + $this->strings = array(); + } + } + if (isset($this->strings[$name])) + { + return $this->strings[$name]; + } + return get_lang($name); + } + +} \ No newline at end of file diff --git a/main/lang/french/plugin_rss.inc.php b/main/lang/french/plugin_rss.inc.php deleted file mode 100644 index dd6de200fb..0000000000 --- a/main/lang/french/plugin_rss.inc.php +++ /dev/null @@ -1,11 +0,0 @@ - - */ - - -$title = "Titre"; -$no_rss = "Veuillez configurer "; \ No newline at end of file diff --git a/plugin/rss/index.php b/plugin/rss/index.php index f8f97c7d15..511ad3cbde 100644 --- a/plugin/rss/index.php +++ b/plugin/rss/index.php @@ -1,32 +1,33 @@ get_rss(); -$settings = $plugin_info['settings']; -$rss = isset($plugin_info['rss']) ? $plugin_info['rss'] : ''; -$title = isset($plugin_info['rss_title']) ? $plugin_info['rss_title'] : 'Rss'; +$title = $plugin->get_block_title(); $title = $title ? "

$title

" : ''; +$css = $plugin->get_css(); +$css = $css ? "" : ''; + +$bullet = api_get_path(WEB_PLUGIN_PATH) . '/rss/resources/arrow-bullet.png'; + if (empty($rss)) { echo get_lang('no_rss'); + return; } -$css = array(); -$css[] = file_get_contents(dirname(__FILE__) . '/resources/rss.css'); -$css[] = file_get_contents(dirname(__FILE__) . '/resources/color.css'); -$css = implode($css); + echo<< @@ -52,7 +53,7 @@ echo<< -

$title

+ $title
EOT; diff --git a/plugin/rss/lang/english.php b/plugin/rss/lang/english.php new file mode 100644 index 0000000000..e98e541feb --- /dev/null +++ b/plugin/rss/lang/english.php @@ -0,0 +1,16 @@ + + */ +$strings['plugin_title'] = "Rss"; +$strings['plugin_comment'] = "Display rss content."; + +$strings['rss'] = "Rss"; +$strings['block_title'] = "Block title"; + +$strings['title'] = "Title"; +$strings['no_rss'] = "There is no RSS configured. Please add a RSS"; \ No newline at end of file diff --git a/main/lang/english/plugin_rss.inc.php b/plugin/rss/lang/french.php similarity index 53% rename from main/lang/english/plugin_rss.inc.php rename to plugin/rss/lang/french.php index 7f453d6076..92ec942b4b 100644 --- a/main/lang/english/plugin_rss.inc.php +++ b/plugin/rss/lang/french.php @@ -6,6 +6,8 @@ * @author Laurent Opprecht */ +$strings['plugin_title'] = "Rss"; +$strings['plugin_comment'] = "Affiche le contenu de flux rss."; -$title = "Title"; -$no_rss = "There is no RSS configured. Please add a RSS"; \ No newline at end of file +$strings['title'] = "Titre"; +$strings['no_rss'] = "Veuillez configurer"; \ No newline at end of file diff --git a/plugin/rss/lib/rss_plugin.class.php b/plugin/rss/lib/rss_plugin.class.php new file mode 100644 index 0000000000..9a8de34ffb --- /dev/null +++ b/plugin/rss/lib/rss_plugin.class.php @@ -0,0 +1,38 @@ + + */ +class RssPlugin extends Plugin +{ + + /** + * + * @return RssPlugin + */ + static function create() + { + static $result = null; + return $result ? $result : $result = new self(); + } + + function get_block_title() + { + return $this->get('block_title'); + } + + function get_rss() + { + return $this->get('rss'); + } + + protected function __construct() + { + parent::__construct('1.1', 'Laurent Opprecht', array('block_title' => 'text', 'rss' => 'text')); + } + +} \ No newline at end of file diff --git a/plugin/rss/plugin.php b/plugin/rss/plugin.php index ff0db2c294..f998de58d8 100644 --- a/plugin/rss/plugin.php +++ b/plugin/rss/plugin.php @@ -9,37 +9,8 @@ * @author Laurent Opprecht */ -global $language_files; -$language_files[] = 'plugin_rss'; -$plugin_info['title'] = 'Rss'; -$plugin_info['comment'] = 'Rss'; -$plugin_info['version'] = '1.1'; -$plugin_info['author'] = 'Laurent Opprecht'; +require_once api_get_path(LIBRARY_PATH) . '/plugin.class.php'; +require_once dirname(__FILE__) . '/lib/rss_plugin.class.php'; - -$rss = ''; -$title = ''; -$plugin_settings = api_get_settings_params(array("subkey = ? AND category = ? AND type = ? " => array('rss', 'Plugins', 'setting'))); -$plugin_settings = $plugin_settings ? $plugin_settings : array(); -foreach ($plugin_settings as $setting) -{ - if ($setting['variable'] == 'rss_rss') - { - $rss = $setting['selected_value']; - } - else if ($setting['variable'] == 'rss_title') - { - $title = $setting['selected_value']; - } -} - -$form = new FormValidator('rss'); -$form->addElement('text', 'title', get_lang('title')); -$form->addElement('text', 'rss', 'Rss'); -$form->addElement('style_submit_button', 'submit_button', get_lang('Save')); -$form->setDefaults(array('rss' => $rss, 'title' => $title)); - -$plugin_info['settings_form'] = $form; -$plugin_info['rss'] = $rss; -$plugin_info['rss_title'] = $title; +$plugin_info = RssPlugin::create()->get_info(); diff --git a/plugin/rss/readme.txt b/plugin/rss/readme.txt new file mode 100644 index 0000000000..1ebcbe17b1 --- /dev/null +++ b/plugin/rss/readme.txt @@ -0,0 +1,4 @@ +Display RSS feeds using the Google Dynamic Feed control. +

+See http://www.google.com/uds/solutions/dynamicfeed/index.html for further information. +

\ No newline at end of file