/** * Inserts the shareaholic content meta tags on the page * On all pages, it will insert the standard content meta tags * On full post pages, it will insert page specific content meta tags * */ public static function insert_content_meta_tags($node = NULL, $view_mode = NULL, $lang_code = NULL) { if ($view_mode === 'rss') { return; } $site_name = ShareaholicUtilities::site_name(); $api_key = ShareaholicUtilities::get_option('api_key'); $module_version = ShareaholicUtilities::get_version(); $content_tags = <<<DOC <!-- Shareaholic Content Tags --> <meta name='shareaholic:site_name' content='{$site_name}' /> <meta name='shareaholic:language' content='{$lang_code}' /> <meta name='shareaholic:site_id' content='{$api_key}' /> <meta name='shareaholic:drupal_version' content='{$module_version}' /> DOC; if (isset($node) && isset($view_mode) && $view_mode === 'full') { $url = $GLOBALS['base_root'] . request_uri(); $published_time = date('c', $node->created); $modified_time = date('c', $node->changed); $author = user_load($node->uid); $author_name = self::get_user_name($author); $tags = implode(', ', self::get_keywords_for($node)); $image_url = self::get_image_url_for($node); $visibility = self::get_visibility($node); $shareable = self::is_shareable($node); $content_tags .= "\n<meta name='shareaholic:url' content='{$url}' />"; $content_tags .= "\n<meta name='shareaholic:article_published_time' content='{$published_time}' />"; $content_tags .= "\n<meta name='shareaholic:article_modified_time' content='{$modified_time}' />"; $content_tags .= "\n<meta name='shareaholic:article_author_name' content='{$author_name}' />"; if (!empty($tags)) { $content_tags .= "\n<meta name='shareaholic:keywords' content='{$tags}' />"; } if (!empty($image_url)) { $content_tags .= "\n<meta name='shareaholic:image' content='{$image_url}' />"; } if (!empty($visibility)) { $content_tags .= "\n<meta name='shareaholic:article_visibility' content='{$visibility}' />"; } if (!empty($shareable)) { $content_tags .= "\n<meta name='shareaholic:shareable_page' content='{$shareable}' />"; } } $content_tags .= "\n<!-- Shareaholic Content Tags End -->\n"; $element = array('#type' => 'markup', '#markup' => $content_tags); drupal_add_html_head($element, 'shareaholic_content_meta_tags'); }
/** * The updating function. This should create a whole configuration * object including share buttons and recommendations as well as * site name and domain to send back to us. */ public static function update() { $version = ShareaholicUtilities::get_version(); $sexybookmarks_configuration = get_option('SexyBookmarks'); $classicbookmarks_configuration = get_option('ShareaholicClassicBookmarks'); $recommendations_configuration = get_option('ShareaholicRecommendations'); $top_bar_configuration = get_option('ShareaholicTopBar'); $new_share_buttons_configuration = self::transform_sexybookmarks_configuration($sexybookmarks_configuration); $new_classicbookmarks_locations = self::transform_classicbookmarks_locations($classicbookmarks_configuration, $sexybookmarks_configuration); $new_top_bar_configuration = self::transform_top_bar_configuration($top_bar_configuration); $location_names = array_map(array('self', 'grab_location_iterator'), $new_share_buttons_configuration['locations_attributes']); // if sexybookmarks are off or not on the bottom if ($sexybookmarks_configuration['sexybookmark'] != '1' || !(bool) preg_grep('/below/', $location_names)) { // then merge in the classic bookmark locations $new_share_buttons_configuration = array_merge($new_share_buttons_configuration, $new_classicbookmarks_locations); } elseif ($sexybookmarks_configuration['sexybookmark'] != '1' || !(bool) preg_grep('/above/', $location_names)) { $new_share_buttons_configuration = array_merge($new_share_buttons_configuration, $new_top_bar_configuration); } $new_recommendations_configuration = array('locations_attributes' => self::transform_recommendations_configuration($recommendations_configuration)); $new_recommendations_configuration = isset($new_recommendations_configuration) ? $new_recommendations_configuration : null; $verification_key = md5(mt_rand()); list($turned_on_share_buttons_location_names, $turned_off_share_buttons_location_names) = self::pad_locations($new_share_buttons_configuration); list($turned_on_recommendations_location_names, $turned_off_recommendations_location_names) = self::pad_locations($new_recommendations_configuration); $new_configuration = array('configuration_publisher' => array('share_buttons_attributes' => $new_share_buttons_configuration, 'recommendations_attributes' => $new_recommendations_configuration, 'site_name' => ShareaholicUtilities::site_name(), 'domain' => ShareaholicUtilities::site_url(), 'verification_key' => $verification_key, 'platform_id' => '12', 'language_id' => ShareaholicUtilities::site_language())); $shortener_configuration = isset($sexybookmarks_configuration['shorty']) ? self::transform_shortener_configuration($sexybookmarks_configuration) : array(); $new_configuration['configuration_publisher'] = array_merge($new_configuration['configuration_publisher'], $shortener_configuration); $response = ShareaholicCurl::post(Shareaholic::API_URL . '/publisher_tools/anonymous', $new_configuration, 'json'); if ($response && preg_match('/20*/', $response['response']['code'])) { ShareaholicUtilities::log_event('6To7ConversionSuccess', array('the_posted_json' => $new_configuration, 'the_created_api_key' => $response['body']['api_key'], 'SexyBookmarks' => $sexybookmarks_configuration, 'ShareaholicClassicBookmarks' => $classicbookmarks_configuration, 'ShareaholicRecommendations' => $recommendations_configuration)); ShareaholicUtilities::update_options(array('api_key' => $response['body']['api_key'], 'version' => Shareaholic::VERSION, 'verification_key' => $verification_key, 'location_name_ids' => $response['body']['location_name_ids'])); ShareaholicUtilities::turn_on_locations(array('share_buttons' => array_flip($turned_on_share_buttons_location_names), 'recommendations' => array_flip($turned_on_recommendations_location_names)), array('share_buttons' => array_flip($turned_off_share_buttons_location_names), 'recommendations' => array_flip($turned_off_recommendations_location_names))); self::transform_wordpress_specific_settings(); self::cleanup_v6_options(); } else { ShareaholicUtilities::log_event('6To7ConversionFailed', array('the_posted_json' => $new_configuration, 'SexyBookmarks' => $sexybookmarks_configuration, 'ShareaholicClassicBookmarks' => $classicbookmarks_configuration, 'ShareaholicRecommendations' => $recommendations_configuration)); } }