diff --git a/SocialBookmarkingPlugin.php b/SocialBookmarkingPlugin.php index 2e5d6f3..4761cbe 100644 --- a/SocialBookmarkingPlugin.php +++ b/SocialBookmarkingPlugin.php @@ -6,9 +6,6 @@ * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3 */ - -require_once dirname(__FILE__) . '/helpers/SocialBookmarkingFunctions.php'; - /** * Social Bookmarking plugin. */ @@ -16,6 +13,7 @@ class SocialBookmarkingPlugin extends Omeka_Plugin_AbstractPlugin { const ADDTHIS_SERVICES_URL = 'http://cache.addthiscdn.com/services/v1/sharing.en.xml'; const SERVICE_SETTINGS_OPTION = 'social_bookmarking_services'; + const ADD_TO_HEADER_OPTION = 'social_bookmarking_add_to_header'; const ADD_TO_OMEKA_ITEMS_OPTION = 'social_bookmarking_add_to_omeka_items'; const ADD_TO_OMEKA_COLLECTIONS_OPTION = 'social_bookmarking_add_to_omeka_collections'; @@ -29,6 +27,7 @@ class SocialBookmarkingPlugin extends Omeka_Plugin_AbstractPlugin 'initialize', 'config_form', 'config', + 'public_header', 'public_items_show', 'public_collections_show' ); @@ -38,16 +37,34 @@ class SocialBookmarkingPlugin extends Omeka_Plugin_AbstractPlugin */ protected $_options = array( 'social_bookmarking_services' => '', + 'social_bookmarking_add_to_header' => '1', 'social_bookmarking_add_to_omeka_items' => '1', 'social_bookmarking_add_to_omeka_collections' => '1', ); + /** + * @var array Default services. + */ + protected $_defaultEnabledServiceCodes = array( + 'facebook', + 'twitter', + 'linkedin', + 'pinterest', + 'email', + 'google', + 'orkut', + 'delicious', + 'digg', + 'stumbleupon', + 'yahoobkm' + ); + /** * Install the plugin. */ public function hookInstall() { - $this->_options['social_bookmarking_services'] = serialize(social_bookmarking_get_default_service_settings()); + $this->_options['social_bookmarking_services'] = serialize($this->_get_default_service_settings()); $this->_installOptions(); } @@ -67,14 +84,14 @@ public function hookUninstall() public function hookUpgrade($args) { $booleanFilter = new Omeka_Filter_Boolean; - $newServiceSettings = social_bookmarking_get_default_service_settings(); - $oldServiceSettings = social_bookmarking_get_service_settings(); + $newServiceSettings = $this->_get_default_service_settings(); + $oldServiceSettings = $this->_get_service_settings(); foreach($newServiceSettings as $serviceCode => $value) { if (array_key_exists($serviceCode, $oldServiceSettings)) { $newServiceSettings[$serviceCode] = $booleanFilter->filter($oldServiceSettings[$serviceCode]); } } - social_bookmarking_set_service_settings($newServiceSettings); + $this->_set_service_settings($newServiceSettings); } /** @@ -86,11 +103,26 @@ public function hookInitialize() } /** - * Display the plugin config form. + * Render the config form. */ public function hookConfigForm() { - require dirname(__FILE__) . '/config_form.php'; + // Set form defaults. + $services = $this->_get_services(); + $serviceSettings = $this->_get_service_settings(); + $setServices = array(); + foreach($services as $serviceCode => $serviceInfo) { + $setServices[$serviceCode] = array_key_exists($serviceCode, $serviceSettings) + ? $serviceSettings[$serviceCode] + : false; + } + + echo get_view()->partial( + 'plugins/social-bookmarking-config-form.php', + array( + 'services' => $services, + 'setServices' => $setServices, + )); } /** @@ -99,45 +131,187 @@ public function hookConfigForm() public function hookConfig($args) { $post = $args['post']; - unset($post['install_plugin']); + set_option(SocialBookmarkingPlugin::ADD_TO_HEADER_OPTION, $post[SocialBookmarkingPlugin::ADD_TO_HEADER_OPTION]); set_option(SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION, $post[SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION]); - unset($post[SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION]); - set_option(SocialBookmarkingPlugin::ADD_TO_OMEKA_COLLECTIONS_OPTION, $post[SocialBookmarkingPlugin::ADD_TO_OMEKA_COLLECTIONS_OPTION]); + + unset($post[SocialBookmarkingPlugin::ADD_TO_HEADER_OPTION]); + unset($post[SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION]); unset($post[SocialBookmarkingPlugin::ADD_TO_OMEKA_COLLECTIONS_OPTION]); - $serviceSettings = social_bookmarking_get_service_settings(); + $serviceSettings = $this->_get_service_settings(); $booleanFilter = new Omeka_Filter_Boolean; foreach($post as $key => $value) { if (array_key_exists($key, $serviceSettings)) { $serviceSettings[$key] = $booleanFilter->filter($value); } + else { + $serviceSettings[$key] = false; + } } - social_bookmarking_set_service_settings($serviceSettings); + $this->_set_service_settings($serviceSettings); } - public function hookPublicItemsShow() + /** + * Hook for public header. + */ + public function hookPublicHeader($args) + { + if (get_option(SocialBookmarkingPlugin::ADD_TO_HEADER_OPTION) == '1') { + $view = $args['view']; + $vars = $view->getVars(); + $request = Zend_Controller_Front::getInstance()->getRequest(); + $params = $request->getParams(); + + // We need absolute urls and getRequestUri() doesn't return domain. + $url = WEB_ROOT . $request->getPathInfo(); + if ($params['action'] == 'show' && in_array($params['controller'], array( + 'collections', + 'items', + 'files', + ))) { + $recordType = $view->singularize($params['controller']); + $record = get_current_record($recordType); + $title = isset($vars['title']) + ? $vars['title'] + : strip_formatting(metadata($record, array('Dublin Core', 'Title'))); + $description = strip_formatting(metadata($record, array('Dublin Core', 'Description'))); + } + else { + $title= isset($vars['title']) ? $vars['title'] : get_option('site_title'); + $description = ''; + } + echo $view->partial('social-bookmarking-toolbar.php', array( + 'url' => $url, + 'title' => $title, + 'description' => $description, + 'services' => $this->_get_services(), + 'serviceSettings' => $this->_get_service_settings(), + )); + } + } + + /** + * Hook for public items show view. + */ + public function hookPublicItemsShow($args) { if (get_option(SocialBookmarkingPlugin::ADD_TO_OMEKA_ITEMS_OPTION) == '1') { - $item = get_current_record('item'); + $view = $args['view']; + $item = $args['item']; $url = record_url($item, 'show', true); $title = strip_formatting(metadata($item, array('Dublin Core', 'Title'))); $description = strip_formatting(metadata($item, array('Dublin Core', 'Description'))); echo '
- $serviceInfo): - if (array_key_exists($serviceCode, $serviceSettings)) { - $value = $serviceSettings[$serviceCode]; - } else { - $value = false; - } - ?> --
- formCheckbox($serviceCode, true, array('checked'=>(boolean)$value)); ?>
-
-
-
+
+ $serviceInfo): ?> +-
+ formCheckbox($serviceCode, true, array('checked' => (boolean) $setServices[$serviceCode])); ?>
+
+
+