/[drupal]/contributions/modules/sharethis/sharethis.module
ViewVC logotype

Diff of /contributions/modules/sharethis/sharethis.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.5.2.2, Wed Mar 25 21:52:28 2009 UTC revision 1.1.2.5.2.3, Tue Aug 18 17:10:33 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: sharethis.module,v 1.1.2.5.2.1 2009/03/16 19:10:20 robloach Exp $  // $Id: sharethis.module,v 1.1.2.5.2.2 2009/03/25 21:52:28 robloach Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 121  function sharethis_nodeapi(&$node, $op, Line 121  function sharethis_nodeapi(&$node, $op,
121          if (variable_get('sharethis_sharethis_this_where', 'links') == 'nodes') {          if (variable_get('sharethis_sharethis_this_where', 'links') == 'nodes') {
122            if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) {            if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) {
123              if (sharethis_add_js()) {              if (sharethis_add_js()) {
124                $sharethis = sharethis_get_js($node->title, array(                $sharethis = sharethis_get_js($node->title, url('node/'. $node->nid, NULL, NULL, TRUE));
                 'url' => url('node/'. $node->nid, NULL, NULL, TRUE),  
               ));  
125                $node->content['sharethis_sharethis_this'] = array(                $node->content['sharethis_sharethis_this'] = array(
126                  '#value' => $sharethis,                  '#value' => $sharethis,
127                  '#weight' => variable_get('sharethis_sharethis_weight', 0),                  '#weight' => variable_get('sharethis_sharethis_weight', 0),
# Line 144  function sharethis_link($type, $node = N Line 142  function sharethis_link($type, $node = N
142      if (variable_get('sharethis_sharethis_this_where', 'links') == 'links') {      if (variable_get('sharethis_sharethis_this_where', 'links') == 'links') {
143        if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) {        if (_sharethis_sharethis_this_show($node->type, $node->nid) && user_access('use share this')) {
144          if (sharethis_add_js()) {          if (sharethis_add_js()) {
145            $sharethis = sharethis_get_js($node->title, array(            $sharethis = sharethis_get_js($node->title, url('node/'. $node->nid, NULL, NULL, TRUE));
             'url' => url('node/'. $node->nid, NULL, NULL, TRUE),  
           ));  
146            $links['sharethis_sharethis_this'] = array(            $links['sharethis_sharethis_this'] = array(
147              'title' => $sharethis,              'title' => $sharethis,
148              'html' => TRUE,              'html' => TRUE,
# Line 190  function _sharethis_sharethis_this_show( Line 186  function _sharethis_sharethis_this_show(
186   */   */
187  function sharethis_add_js() {  function sharethis_add_js() {
188    static $added = FALSE;    static $added = FALSE;
189    if ($added === FALSE) {    if ($added == FALSE) {
190      $code = variable_get('sharethis_sharethis_this_code', 0);      $added = TRUE;
191      if (!empty($code)) {      $code = variable_get('sharethis_sharethis_this_code', '');
192        drupal_set_html_head($code);      if (empty($code)) {
193        $added = TRUE;        $code = 'http://w.sharethis.com/button/sharethis.js#publisher=00000000-0000-0000-0000-000000000000&amp;type=website';
194      }      }
195        else {
196          $code = str_replace(array('<script type="text/javascript" src="', '"></script>'), array('', ''), $code);
197        }
198        drupal_add_js(drupal_get_path('module', 'sharethis').'/sharethis.js');
199        drupal_set_html_head('<script type="text/javascript" src="'. $code .'&amp;button=false"></script>');
200    }    }
201    return $added;    return $added;
202  }  }
# Line 203  function sharethis_add_js() { Line 204  function sharethis_add_js() {
204  /**  /**
205   * Creates the complete script tag to create SHARETHIS elements.   * Creates the complete script tag to create SHARETHIS elements.
206   *   *
207   * See http://sharethis.com/publisher?type=stapi for the options available.   * See  for the options available.
208   */   *
209  function sharethis_get_js($title, $options = array()) {   * @param $title
210    $options['title'] = $title;   *   The name of the article.
211    return "<script language='javascript' type='text/javascript'>SHARETHIS.addEntry(". drupal_to_js($options) . ', {button:true} );</script>';   * @param $options
212     *   The options to be passed (http://sharethis.com/publisher?type=stapi).
213     * @param $chicklet
214     *   (optional) The name of the chicklet to pass if desired (email, twitter, etc).
215     */
216    function sharethis_get_js($title, $url, $chicklet = 'sharethis') {
217      sharethis_add_js();
218      $title = check_plain($title);
219      $chickletname = $chicklet == 'sharethis' ? t('ShareThis') : ucfirst($chicklet);
220      $image = drupal_get_path('module', 'sharethis') ."/images/$chicklet.gif";
221      return theme('sharethis', $title, $url, $chicklet, $chickletname, $image);
222    }
223    
224    function theme_sharethis($title, $url, $chicklet = 'sharethis', $chickletname = 'ShareThis', $image) {
225      return "<a href='$url' title='$title' rel='nofollow' name='$chicklet' class='sharethis-button'><img src='$image' /> $chickletname</a>";
226  }  }

Legend:
Removed from v.1.1.2.5.2.2  
changed lines
  Added in v.1.1.2.5.2.3

  ViewVC Help
Powered by ViewVC 1.1.2