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

Diff of /contributions/modules/service_links/service_links.module

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

revision 1.26.4.4, Sat Apr 11 18:10:48 2009 UTC revision 1.26.4.5, Fri Aug 14 00:36:27 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: service_links.module,v 1.26.4.4 2009/04/11 18:10:48 thecrow Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 226  function service_links_theme() { Line 226  function service_links_theme() {
226  }  }
227    
228  /**  /**
229     * Discover all available service links by invoking hook_service_links().
230     *
231     * @param $services
232     *   If NULL, will retrieve all service link information. If an array is passed,
233     *   will only obtain information for the given keyed links.
234     * @param $reset
235     *   Resets the Service Links cache.
236     *
237     * @return
238     *   An array containing information for all the requested services.
239     */
240    function service_links_get_links($services = NULL, $reset = FALSE) {
241      static $links = NULL;
242      if (!isset($links) || $reset) {
243        // Retrieve the links from the cache.
244        if (!$reset && ($cache = cache_get('service_links_get_links')) && !empty($cache->data)) {
245          $links = $cache->data;
246        }
247        else {
248          // Create the repository of links.
249          $links = array();
250          foreach (module_implements('service_links') as $module) {
251            $module_links = module_invoke($module, 'service_links');
252            foreach ($module_links as $name => $link) {
253              $link['module'] = $module;
254              $links[$name] = $link;
255            }
256          }
257          // Allow alteration of the links.
258          drupal_alter('service_links', $links);
259    
260          // Save the links in the cache.
261          cache_set('service_links_get_links', $links);
262        }
263      }
264      // If desired, return only the given services.
265      return isset($services) ? array_intersect_key($links, $services) : $links;
266    }
267    
268    /**
269   * Create short links using predefined settings   * Create short links using predefined settings
270   */   */
271  function service_links_short_url($url, $nid) {  function service_links_short_url($url, $nid) {
# Line 253  function service_links_short_url($url, $ Line 293  function service_links_short_url($url, $
293  function service_links_render($node, $nodelink = FALSE, $style = 0) {  function service_links_render($node, $nodelink = FALSE, $style = 0) {
294    $links = array();    $links = array();
295    $settings = _service_links_load_settings();    $settings = _service_links_load_settings();
296    $services = module_invoke_all('service_links');    $services = service_links_get_links(array_filter($settings['link_show']));
297    
298    if ($settings['agg2_link'] && $node->link) {    if ($settings['agg2_link'] && $node->link) {
299      $url = ($node->source_link ? $node->source_link : $node->link);      $url = ($node->source_link ? $node->source_link : $node->link);
# Line 280  function service_links_render($node, $no Line 320  function service_links_render($node, $no
320        break;        break;
321    }    }
322    
323    $settings['tag'] = array('<encoded-title>', '<encoded-url>', '<teaser>','<short-url>', '<source>', '<node-id>', '<url>', '<title>');    $settings['tag'] = array(
324    $settings['subst'] = array(urlencode($node->title), urlencode($url), urlencode(strip_tags($node->teaser)), urlencode($short_url), urlencode(variable_get('site_name', 'Drupal')), $node->nid, $url, $node->title);      'encoded-title' => '<encoded-title>',
325        'encoded-url' => '<encoded-url>',
326        'encoded-teaser' => '<encoded-teaser>',
327        'teaser' => '<teaser>',
328        'short-url' => '<short-url>',
329        'source' => '<source>',
330        'node-id' => '<node-id>',
331        'url' => '<url>',
332        'title' => '<title>',
333      );
334      $settings['subst'] = array(
335        'encoded-title' => urlencode($node->title),
336        'encoded-url' => urlencode($url),
337        'encoded-teaser' => urlencode(strip_tags($node->teaser)),
338        'teaser' => $node->teaser,
339        'short-url' => urlencode($short_url),
340        'source' => urlencode(variable_get('site_name', 'Drupal')),
341        'node-id' => $node->nid,
342        'url' => $url,
343        'title' => $node->title,
344      );
345    
346    if ($style > 0) $settings['style'] = $style;    if ($style > 0) $settings['style'] = $style;
347    
348    foreach($services as $service_id => $service) {    foreach($services as $service_id => $service) {
349      if ($settings['link_show'][$service_id]) {      $links['weight'][] = isset($settings['link_weight'][$service_id]) ? $settings['link_weight'][$service_id] : 0;
350        $links['weight'][] = isset($settings['link_weight'][$service_id]) ? $settings['link_weight'][$service_id] : 0;  
351        $service['url'] = split('\?', $service['link']);
352        $service['url'] = split('\?', $service['link']);      $subst_id = isset($service['url'][1]) ? 1 : 0;
353        $subst_id = isset($service['url'][1]) ? 1 : 0;      $service['url'][$subst_id] = str_replace($settings['tag'], $settings['subst'], $service['url'][$subst_id]);
354        $service['url'][$subst_id] = str_replace($settings['tag'], $settings['subst'], $service['url'][$subst_id]);  
355        $service['attributes']['title'] = $service['description'];
356        $service['attributes']['title'] = $service['description'];      $service['attributes']['id'] = form_clean_id('service_links-'. $service_id);
357        $service['attributes'] += $settings['attributes'];      $service['attributes'] += $settings['attributes'];
358    
359        $service['icon'] = isset($service['icon']) ? $service['icon'] : $service_id .'.png';      $service['icon'] = isset($service['icon']) ? $service['icon'] : drupal_get_path('module', 'service_links') ."/images/$service_id.png";
360    
361        $service_id = str_replace('__', '_', 'service_links_'. $service_id);      $service_id = str_replace('__', '_', 'service_links_'. $service_id);
362        $links['link'][$service_id] = theme('service_links_build_link',  
363          $service['name'], $service['url'],      // Add the related JavaScript and CSS.
364          array(0 => $settings['images_path'], 1 => $service['icon']),      if (isset($service['javascript'])) {
365          $nodelink, $settings['style'], $service['attributes']);        drupal_add_js($service['javascript']);
366        }
367        if (isset($service['css'])) {
368          drupal_add_js($service['css']);
369        }
370    
371        if (isset($service['javascript'])) drupal_add_js($settings['js_path'] . $service['javascript']);      // Invoke callback function.
372        if (isset($service['callback'])) {
373          call_user_func($service['callback'], $service, $settings['subst']);
374      }      }
375    
376        // Create the HTML.
377        $links['link'][$service_id] = theme('service_links_build_link',
378          $service['name'],
379          $service['url'],
380          $service['icon'],
381          $nodelink,
382          $settings['style'],
383          $service['attributes']
384        );
385    }    }
386    
387    if (!empty($links['link'])) array_multisort($links['weight'], $links['link']);    if (!empty($links['link'])) array_multisort($links['weight'], $links['link']);
388    return $links['link'];    return $links['link'];
389  }  }
390    
391  function theme_service_links_build_link($text, $url = array(), $image = array(), $nodelink, $style, $attributes = array()) {  function theme_service_links_build_link($text, $url = array(), $image = NULL, $nodelink, $style, $attributes = array()) {
392    if ($nodelink) {    if ($nodelink) {
393      switch ($style) {      switch ($style) {
394        case SERVICE_LINKS_STYLE_TEXT:        case SERVICE_LINKS_STYLE_TEXT:
# Line 325  function theme_service_links_build_link( Line 401  function theme_service_links_build_link(
401          break;          break;
402        case SERVICE_LINKS_STYLE_IMAGE:        case SERVICE_LINKS_STYLE_IMAGE:
403          $link = array(          $link = array(
404            'title' => theme('image', implode('', $image), $text),            'title' => theme('image', $icon, $text),
405            'href' => $url[0],            'href' => $url[0],
406            'query' => $url[1],            'query' => $url[1],
407            'attributes' => $attributes,            'attributes' => $attributes,
# Line 334  function theme_service_links_build_link( Line 410  function theme_service_links_build_link(
410          break;          break;
411        case SERVICE_LINKS_STYLE_IMAGE_AND_TEXT:        case SERVICE_LINKS_STYLE_IMAGE_AND_TEXT:
412          $link = array(          $link = array(
413            'title' => theme('image', implode('', $image), $text) .' '. $text,            'title' => theme('image', $image, $text) .' '. $text,
414            'href' => $url[0],            'href' => $url[0],
415            'query' => $url[1],            'query' => $url[1],
416            'attributes' => $attributes,            'attributes' => $attributes,
# Line 351  function theme_service_links_build_link( Line 427  function theme_service_links_build_link(
427          break;          break;
428        case SERVICE_LINKS_STYLE_IMAGE:        case SERVICE_LINKS_STYLE_IMAGE:
429          $attributes = array_merge($attributes, array('html' => TRUE));          $attributes = array_merge($attributes, array('html' => TRUE));
430          $link = l(theme('image', implode('', $image), $text), $url[0], $attributes);          $link = l(theme('image', $image, $text), $url[0], $attributes);
431          break;          break;
432        case SERVICE_LINKS_STYLE_IMAGE_AND_TEXT:        case SERVICE_LINKS_STYLE_IMAGE_AND_TEXT:
433          $attributes = array_merge($attributes, array('html' => TRUE));          $attributes = array_merge($attributes, array('html' => TRUE));
434          $link = l(theme('image', implode('', $image), $text) .' '. $text, $url[0], $attributes);          $link = l(theme('image', $image, $text) .' '. $text, $url[0], $attributes);
435          break;          break;
436        case SERVICE_LINKS_STYLE_FISHEYE:        case SERVICE_LINKS_STYLE_FISHEYE:
437          $image[0] = $image[0] . variable_get('service_links_fisheye_folder', '');          $image[0] = $image[0] . variable_get('service_links_fisheye_folder', '');
438          $attributes['attributes']['class'] = isset($attributes['attributes']['class']) ? $attributes['attributes']['class'] .' fisheyeItem' : 'fisheyeItem' ;          $attributes['attributes']['class'] = isset($attributes['attributes']['class']) ? $attributes['attributes']['class'] .' fisheyeItem' : 'fisheyeItem' ;
439          $attributes = array_merge($attributes, array('html' => TRUE));          $attributes = array_merge($attributes, array('html' => TRUE));
440          $link = l(theme('image', implode('', $image), $text, NULL, NULL, FALSE) .'<span>'. $text .'</span>', $url[0], $attributes);          $link = l(theme('image', $image, $text, NULL, NULL, FALSE) .'<span>'. $text .'</span>', $url[0], $attributes);
441          break;          break;
442      }      }
443    }    }
# Line 439  function _service_links_load_settings() Line 515  function _service_links_load_settings()
515    $settings['link_weight'] = variable_get('service_links_weight', NULL);    $settings['link_weight'] = variable_get('service_links_weight', NULL);
516    $settings['link_show'] = variable_get('service_links_show', NULL);    $settings['link_show'] = variable_get('service_links_show', NULL);
517    
   $settings['js_path'] = drupal_get_path('module', 'service_links');  
   $settings['images_path'] = $settings['js_path']  .'/images/';  
   $settings['js_path'] = $settings['js_path'] .'/js/';  
   
518    $settings['agg2_link'] = variable_get('service_links_agg2_link', 0);    $settings['agg2_link'] = variable_get('service_links_agg2_link', 0);
519    
520    return $settings;    return $settings;

Legend:
Removed from v.1.26.4.4  
changed lines
  Added in v.1.26.4.5

  ViewVC Help
Powered by ViewVC 1.1.2