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

Diff of /contributions/modules/follow/follow.module

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

revision 1.5, Fri Oct 30 22:00:08 2009 UTC revision 1.6, Mon Nov 2 20:25:53 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: follow.module,v 1.4 2009/10/30 21:13:50 pwolanin Exp $  // $Id: follow.module,v 1.5 2009/10/30 22:00:08 pwolanin Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 104  function follow_theme() { Line 104  function follow_theme() {
104    $items = array();    $items = array();
105    
106    $items['follow_links_form'] = array(    $items['follow_links_form'] = array(
107      'variables' => array('form' => array()),      'render element' => 'form',
108    );    );
109    $items['follow_links'] = array(    $items['follow_links'] = array(
110      'variables' => array('links' => array(), 'networks' => array()),      'variables' => array('links' => array(), 'networks' => array()),
# Line 259  function _follow_block_content($uid = 0) Line 259  function _follow_block_content($uid = 0)
259    $output = '';    $output = '';
260    
261    if ($links = follow_links_load($uid)) {    if ($links = follow_links_load($uid)) {
262      $output = theme('follow_links', $links, follow_networks_load());      $output = theme('follow_links', array('links' => $links, 'networks' => follow_networks_load($uid)));
263      $output .= _follow_block_config_links($uid);      $output .= _follow_block_config_links($uid);
264    }    }
265    
# Line 279  function _follow_block_content($uid = 0) Line 279  function _follow_block_content($uid = 0)
279  function theme_follow_links($variables) {  function theme_follow_links($variables) {
280    $links = $variables['links'];    $links = $variables['links'];
281    $networks = $variables['networks'];    $networks = $variables['networks'];
282    $output = '<div class="follow-links clear-block">';    $output = '<div class="follow-links clearfix">';
283    
284    foreach($links as $link) {    foreach($links as $link) {
285      $title = $networks[$link->name];      $title = $networks[$link->name];
286      $output .= theme('follow_link', $link, $title);      $output .= theme('follow_link', array('link' => $link, 'title' => $title));
287    }    }
288    
289    $output .= '</div>';    $output .= '</div>';
# Line 363  function _follow_block_config_links($uid Line 363  function _follow_block_config_links($uid
363   *   *
364   * @ingroup forms   * @ingroup forms
365   */   */
366   function follow_links_form($form, &$form_state, $uid = 0) {  function follow_links_form($form, &$form_state, $uid = 0) {
367    $form = array();    $form = array();
368    
369    $form['uid'] = array('#type' => 'hidden', '#value' => $uid);    $form['uid'] = array('#type' => 'hidden', '#value' => $uid);
370    $form['follow_links']['#tree'] = TRUE;    $form['follow_links']['#tree'] = TRUE;
371    
372    $links = follow_links_load($uid);    $links = follow_links_load($uid);
373    $networks = follow_networks_load(TRUE);    $networks = follow_networks_load($uid, TRUE);
374    
375    // Put all our existing links at the top, sorted by weight.    // Put all our existing links at the top, sorted by weight.
376    if (is_array($links)) {    if (is_array($links)) {
# Line 399  function _follow_links_form_link($link, Line 399  function _follow_links_form_link($link,
399    $elements = array();    $elements = array();
400    
401    $elements['name'] = array(    $elements['name'] = array(
402      '#type' => 'markup',      '#markup' => $title,
     '#value' => $title,  
403    );    );
404    if (isset($link->lid)) {    if (isset($link->lid)) {
405      $elements['lid'] = array(      $elements['lid'] = array(
# Line 409  function _follow_links_form_link($link, Line 408  function _follow_links_form_link($link,
408      );      );
409      $elements['weight'] = array(      $elements['weight'] = array(
410        '#type' => 'weight',        '#type' => 'weight',
411        '#default_value' => $links->weight,        '#default_value' => $link->weight,
412      );      );
413    }    }
414    $elements['url'] = array(    $elements['url'] = array(
# Line 468  function follow_links_form_submit($form, Line 467  function follow_links_form_submit($form,
467   * @ingroup themeable   * @ingroup themeable
468   * @ingroup forms   * @ingroup forms
469   */   */
470  function theme_follow_links_form($form) {  function theme_follow_links_form($variables) {
471    $form = $form['form'];    $form = $variables['form'];
472    $rows = array();    $rows = array();
473    $disabled_rows = array();    $disabled_rows = array();
474    
475    foreach (element_children($form['follow_links']) as $key) {    foreach (element_children($form['follow_links']) as $key) {
476      $row = array();      $row = array();
     $disabled_row = array();  
477    
478      if (isset($form['follow_links'][$key]['weight'])) {      if (isset($form['follow_links'][$key]['weight'])) {
479        $row[] = drupal_render($form['follow_links'][$key]['lid']) . drupal_render($form['follow_links'][$key]['name']);        $row[] = drupal_render($form['follow_links'][$key]['lid']) . drupal_render($form['follow_links'][$key]['name']);
480        $row[] = drupal_render($form['follow_links'][$key]['url']);        $row[] = drupal_render($form['follow_links'][$key]['url']);
481    
482        // Now, render the weight row.        // Now, render the weight row.
483        $form['follow_links'][$key]['weight']['#attributes']['class'] = 'follow-links-weight';        $form['follow_links'][$key]['weight']['#attributes']['class'][] = 'follow-links-weight';
484        $row[] = drupal_render($form['follow_links'][$key]['weight']);        $row[] = drupal_render($form['follow_links'][$key]['weight']);
485    
486        // Add the new row to our collection of rows, and give it the 'draggable' class.        // Add the new row to our collection of rows, and give it the 'draggable' class.
487        $rows[] = array(        $rows[] = array(
488          'data' => $row,          'data' => $row,
489          'class' => 'draggable',          'class' => array('draggable'),
490        );        );
491      }      }
492      else {      else {
# Line 507  function theme_follow_links_form($form) Line 505  function theme_follow_links_form($form)
505    if (count($disabled_rows)) {    if (count($disabled_rows)) {
506      $output .= theme('table', array('header' => $disabled_header, 'rows' => $disabled_rows));      $output .= theme('table', array('header' => $disabled_header, 'rows' => $disabled_rows));
507    }    }
508    $output .= drupal_render($form);    $output .= drupal_render_children($form);
509    
510    drupal_add_tabledrag('follow-links-weighted-form', 'order', 'self', 'follow-links-weight');    drupal_add_tabledrag('follow-links-weighted-form', 'order', 'self', 'follow-links-weight');
511    
# Line 575  function follow_link_delete($lid) { Line 573  function follow_link_delete($lid) {
573      ->execute();      ->execute();
574  }  }
575    
   
576  /**  /**
577   * Loads all follow networks   * Loads all follow networks
578   *   *
# Line 585  function follow_link_delete($lid) { Line 582  function follow_link_delete($lid) {
582   * @return   * @return
583   *   An array of network names, keys are machine names, values are visible titles.   *   An array of network names, keys are machine names, values are visible titles.
584   */   */
585  function follow_networks_load($reset = FALSE) {  function follow_networks_load($uid, $reset = FALSE) {
586    static $networks = array();    static $networks = array();
587    
588    // Clear cache if $reset is TRUE;    // Clear cache if $reset is TRUE;
589    if ($reset) {    if ($reset) {
590      $networks = array();      $networks = array();
     cache_clear_all('follow:networks', 'cache');  
591    }    }
592    // Return presets if the array is populated.    // Return presets if the array is populated.
593    if (!empty($networks)) {    if (empty($networks[$uid])) {
594      return $networks;      // We call hook_follow_networks_alter() to allow other modules to create
595        // or alter networks.
596        $networks[$uid] = follow_default_networks($uid);
597        drupal_alter('follow_networks', $networks, $uid);
598    }    }
599    
600    // Grab from cache or build the array of networks.    return $networks[$uid];
   if (($cache = cache_get('follow:networks', 'cache')) && is_array($cache->data)) {  
     $networks = $cache->data;  
   }  
   else {  
     // We don't have an API to create new networks yet, so for now, we only call hook_follow_networks().  
     $networks = module_invoke_all('follow_networks');  
     cache_set('follow:networks', $networks);  
   }  
   return $networks;  
601  }  }
602    
603  /**  /**
# Line 616  function follow_networks_load($reset = F Line 606  function follow_networks_load($reset = F
606   * @return   * @return
607   *   An array of network names, keys are machine names, values are visible titles.   *   An array of network names, keys are machine names, values are visible titles.
608   */   */
609  function follow_follow_networks() {  function follow_default_networks($uid) {
610    return array(    $networks = array(
611      'facebook'  => t('Facebook'),      'facebook'  => t('Facebook'),
612      'virb'      => t('Virb'),      'virb'      => t('Virb'),
613      'myspace'   => t('MySpace'),      'myspace'   => t('MySpace'),
# Line 632  function follow_follow_networks() { Line 622  function follow_follow_networks() {
622      'delicious' => t('Delicious'),      'delicious' => t('Delicious'),
623      'tumblr'    => t('Tumblr'),      'tumblr'    => t('Tumblr'),
624    );    );
625      if ($uid == 0) {
626        $networks['self'] = t('This site');
627      }
628      return $networks;
629  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.2