| Commit | Line | Data |
|---|---|---|
| 754744f1 PP |
1 | <?php |
| 2 | ||
| 680a3f59 | 3 | /** |
| 68bf8a8b | 4 | * @file |
| 49a81891 JP |
5 | * Hook implementations for the AddThis-module. Most of the logic is defined |
| 6 | * in a separate AddThis-class to keep the .module-file clean. | |
| 68bf8a8b | 7 | */ |
| 680a3f59 | 8 | |
| 465ccab2 JP |
9 | module_load_include('inc', 'addthis', 'includes/addthis.block'); |
| 10 | module_load_include('inc', 'addthis', 'includes/addthis.field'); | |
| 211164bd | 11 | |
| 680a3f59 | 12 | /** |
| b3ac575e | 13 | * Implements hook_help(). |
| 680a3f59 | 14 | */ |
| b3ac575e VP |
15 | function addthis_help($path, $arg) { |
| 16 | switch ($path) { | |
| 17 | case 'admin/help#addthis': | |
| 591b038e | 18 | $output = '<h3>' . t('About') . '</h3>'; |
| fd5135b5 | 19 | $output .= '<p>' . t("The AddThis module defines AddThis field type for the Field module. A AddThis field may contain a button, toolbox, sharecount or customized sharing tool using <a href=\"http://addthis.com/\">AddThis.com</a>.") . '</p>'; |
| b3ac575e VP |
20 | return $output; |
| 21 | } | |
| 22 | } | |
| 23 | ||
| 24 | /** | |
| b3ac575e VP |
25 | * Implements hook_filter_format_update(). |
| 26 | */ | |
| 27 | function addthis_filter_format_update($format) { | |
| 28 | field_cache_clear(); | |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * Implements hook_filter_format_disable(). | |
| 33 | */ | |
| 34 | function addthis_filter_format_disable($format) { | |
| 35 | field_cache_clear(); | |
| d222a229 | 36 | } |
| 2422fd60 | 37 | |
| 7a62f979 JP |
38 | |
| 39 | /** | |
| 40 | * Implements hook_menu(). | |
| 41 | */ | |
| 42 | function addthis_menu() { | |
| 43 | $menuItems['admin/config/system/addthis'] = array( | |
| 44 | 'title' => 'AddThis', | |
| 45 | 'description' => 'Configure AddThis settings.', | |
| 46 | 'page callback' => 'drupal_get_form', | |
| 47 | 'page arguments' => array('addthis_admin_settings_form'), | |
| 460f1e3c | 48 | 'access arguments' => array(AddThis::PERMISSION_ADMINISTER_ADDTHIS), |
| 7a62f979 | 49 | 'type' => MENU_NORMAL_ITEM, |
| 9268db58 | 50 | 'file' => AddThis::ADMIN_INCLUDE_FILE, |
| 7a62f979 JP |
51 | ); |
| 52 | return $menuItems; | |
| 53 | } | |
| 6fa6aaac JP |
54 | |
| 55 | /** | |
| 56 | * Implements hook_permission(). | |
| 57 | */ | |
| 58 | function addthis_permission() { | |
| 59 | return array( | |
| 460f1e3c | 60 | AddThis::PERMISSION_ADMINISTER_ADDTHIS => array( |
| 6fa6aaac JP |
61 | 'title' => t('Administer AddThis'), |
| 62 | 'description' => t('Perform maintenance tasks for AddThis.'), | |
| 63 | ), | |
| 460f1e3c JP |
64 | AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS => array( |
| 65 | 'title' => t('Administer advanced AddThis'), | |
| 66 | 'description' => t('Perform advanced maintenance tasks for AddThis.'), | |
| 67 | ), | |
| 6fa6aaac JP |
68 | ); |
| 69 | } | |
| aea420e4 JP |
70 | |
| 71 | /** | |
| 72 | * Implements hook_page_alter(). | |
| 73 | */ | |
| 74 | function addthis_page_alter(&$page) { | |
| 4c82025d | 75 | AddThis::getInstance()->addWidgetJs(); |
| 2ee37e69 | 76 | AddThis::getInstance()->addConfigurationOptionsJs(); |
| aea420e4 | 77 | } |
| e0d5a8e5 JP |
78 | |
| 79 | /** | |
| 80 | * Implements hook_form_alter(). | |
| 81 | */ | |
| 82 | function addthis_form_alter(&$form, &$form_state, $form_id) { | |
| 83 | if ($form_id == 'field_ui_field_edit_form' && | |
| 84 | $form['#field']['type'] == AddThis::FIELD_TYPE && | |
| 20f92648 | 85 | $form['#field']['type'] == AddThis::MODULE_NAME) { |
| e0d5a8e5 JP |
86 | // We hide the instance fieldset because we don't hold any value's per instance. |
| 87 | // I know this is a dirty hack to hide it but I'm not aware that there is a way to | |
| 88 | // disable instance value's in the field API. | |
| 89 | $form['field']['#access'] = FALSE; | |
| 90 | $form['instance']['required']['#access'] = FALSE; | |
| 91 | $form['instance']['description']['#access'] = FALSE; | |
| 92 | $form['instance']['default_value_widget']['#access'] = FALSE; | |
| 93 | } | |
| 94 | } | |
| 5b48493d JP |
95 | |
| 96 | /** | |
| 97 | * Implementation of hook_theme(). | |
| 98 | */ | |
| 99 | function addthis_theme($existing, $type, $theme, $path) { | |
| 100 | return array( | |
| 25b6bbc6 MG |
101 | 'addthis_wrapper' => array( |
| 102 | 'render element' => 'addthis_wrapper' | |
| 103 | ), | |
| 5b48493d JP |
104 | 'addthis_element' => array( |
| 105 | 'render element' => 'addthis_element' | |
| 25b6bbc6 MG |
106 | ), |
| 107 | 'addthis' => array( | |
| d87800e9 | 108 | 'render element' => 'addthis' |
| 5b48493d JP |
109 | ) |
| 110 | ); | |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 25b6bbc6 MG |
114 | * Implementation hook_preprocess() for theme_addthis. |
| 115 | */ | |
| 116 | function template_preprocess_addthis(&$variables) { | |
| d87800e9 MG |
117 | // Set the correct display information |
| 118 | $display_type = NULL; | |
| 119 | if (isset($variables[0]) && count($variables) == 3) { | |
| 120 | $variables['display'] = $variables[0]; | |
| 121 | unset($variables[0]); | |
| 122 | } elseif (isset($variables['display'])) { | |
| 123 | $display_type = $variables['display']; | |
| 124 | } | |
| 125 | ||
| 126 | // Get formatters | |
| 127 | $addthis_formatters = addthis_field_info_formatter_field_type(); | |
| 25b6bbc6 MG |
128 | } |
| 129 | ||
| 130 | function theme_addthis($variables) { | |
| d87800e9 MG |
131 | //dpm($variables); |
| 132 | //return render($variables); | |
| 133 | return ''; | |
| 25b6bbc6 MG |
134 | } |
| 135 | ||
| 136 | function theme_addthis_wrapper($variables) { | |
| 137 | // Get the element | |
| 138 | $element = $variables['addthis_wrapper']; | |
| 139 | ||
| 140 | // Render the html | |
| 141 | $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>'; | |
| 142 | ||
| 143 | $children = element_children($element); | |
| 144 | if (count($children) > 0) { | |
| 145 | foreach($children as $child) { | |
| 146 | $output .= render($element[$child]); | |
| 147 | } | |
| 148 | } | |
| 149 | $output .= '</' . $element['#tag'] . ">\n"; | |
| 150 | return $output; | |
| 151 | } | |
| 152 | ||
| 153 | /** | |
| 5b48493d JP |
154 | * Theme the elements that are created in the AddThis module. This is |
| 155 | * created with hook_addthis_element. | |
| 156 | */ | |
| 157 | function theme_addthis_element($variables) { | |
| 158 | // Get the element | |
| 159 | $element = $variables['addthis_element']; | |
| 160 | ||
| 5b48493d JP |
161 | // Render the html |
| 162 | if (!isset($element['#value'])) { | |
| 163 | return '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n"; | |
| 164 | } | |
| 165 | else { | |
| 166 | $output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>'; | |
| 167 | if (isset($element['#value_prefix'])) { | |
| 168 | $output .= $element['#value_prefix']; | |
| 169 | } | |
| 170 | $output .= $element['#value']; | |
| 171 | if (isset($element['#value_suffix'])) { | |
| 172 | $output .= $element['#value_suffix']; | |
| 173 | } | |
| 174 | $output .= '</' . $element['#tag'] . ">\n"; | |
| 175 | return $output; | |
| 176 | } | |
| 177 | } |