/[drupal]/contributions/modules/mysite/contrib/storylink.inc
ViewVC logotype

Diff of /contributions/modules/mysite/contrib/storylink.inc

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

revision 1.5, Sat Jan 5 20:47:55 2008 UTC revision 1.6, Sun Apr 6 23:08:26 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: storylink.inc,v 1.4 2007/10/07 19:09:51 agentken Exp $  // $Id: storylink.inc,v 1.5 2008/01/05 20:47:55 agentken Exp $
 // Submitted by patchak. http://drupal.org/node/91018  
3    
4  /**  /**
5     * @file
6     * Allows users to add storylinks to MySite collections.
7     *
8   * INSTALLATION   * INSTALLATION
9   *   *
10   * Requires: vote_storylink.module from the Vote_Up-Down module   * Requires: vote_storylink.module from the Vote_Up-Down module
# Line 10  Line 12 
12   * Settings: No   * Settings: No
13   *   *
14   * Author: patchak   * Author: patchak
15     *
16     * @ingroup mysite_plugins
17   */   */
18    
19  /**  /**
20   * Implements mysite_type_hook().   * Implements mysite_type_hook().
21   *   *
22   * Storylink module must be enabled for this plugin to register.   * Storylink module must be enabled for this plugin to register.
  *  
23   */   */
24  function mysite_type_storylink($get_options = TRUE) {  function mysite_type_storylink($get_options = TRUE) {
25    if(module_exists('vote_storylink')) {    if (module_exists('vote_storylink')) {
26      $type = array(      $type = array(
27        'name' => t('Storylinks'),        'name' => t('Storylinks'),
28        'description' => t('<b>Storylinks</b>: All storylink posts from a specific user'),        'description' => t('<b>Storylinks</b>: All storylink posts from a specific user'),
29        'include' => 'storylink',        'include' => 'storylink',
30        'prefix' => t('News from '),        'prefix' => t('News from '),
31        'suffix' => t(''),        'suffix' => t(''),
32        'category' => t('Content'),        'category' => t('Content'),
# Line 34  function mysite_type_storylink($get_opti Line 37  function mysite_type_storylink($get_opti
37        'search' => TRUE,        'search' => TRUE,
38      );      );
39      $basic_settings = variable_get('mysite_basic_storylink_settings', array());      $basic_settings = variable_get('mysite_basic_storylink_settings', array());
40      $type = array_merge($type, $basic_settings);      $type = array_merge($type, $basic_settings);
41      if ($get_options) {      if ($get_options) {
42        $type['options'] = mysite_type_storylink_options();        $type['options'] = mysite_type_storylink_options();
43      }      }
# Line 50  function mysite_type_storylink_options() Line 53  function mysite_type_storylink_options()
53    $sql = "SELECT DISTINCT(u.uid), u.name, u.picture FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' ORDER BY u.name";    $sql = "SELECT DISTINCT(u.uid), u.name, u.picture FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' ORDER BY u.name";
54    $result = db_query($sql);    $result = db_query($sql);
55    $storylinks = array();    $storylinks = array();
56    while($item = db_fetch_object($result)) {    while ($item = db_fetch_object($result)) {
57      $storylinks[] =$item;      $storylinks[] =$item;
58    }    }
59    foreach ($storylinks as $key => $value) {    foreach ($storylinks as $key => $value) {
# Line 61  function mysite_type_storylink_options() Line 64  function mysite_type_storylink_options()
64      if (empty($icon)) {      if (empty($icon)) {
65        $icon = array('path' => file_directory_path() .'/'. variable_get('user_picture_path', 'pictures'), 'file' => $value->picture); // this is a special case        $icon = array('path' => file_directory_path() .'/'. variable_get('user_picture_path', 'pictures'), 'file' => $value->picture); // this is a special case
66      }      }
67      $options['icon'][] = $icon;      $options['icon'][] = $icon;
68    }    }
69    return $options;    return $options;
70  }  }
71    
72  /**  /**
73   * Implements mysite_type_hook_title().   * Implements mysite_type_hook_title().
74   */   */
75  function mysite_type_storylink_title($type_id = NULL, $title = NULL) {  function mysite_type_storylink_title($type_id = NULL, $title = NULL) {
76    if(!empty($type_id)) {    if (!empty($type_id)) {
77      if (is_null($title)) {      if (is_null($title)) {
78        $storylink = user_load(array('uid' => $type_id));        $storylink = user_load(array('uid' => $type_id));
79        $title = $storylink->name;        $title = $storylink->name;
80      }      }
81      $type = mysite_type_storylink(FALSE);      $type = mysite_type_storylink(FALSE);
82      $title = $type['prefix'] .' '. $title . t("") .' '. $type['suffix'];      $title = $type['prefix'] .' '. $title . t("") .' '. $type['suffix'];
83      $title = trim(rtrim($title));      $title = trim(rtrim($title));
# Line 85  function mysite_type_storylink_title($ty Line 88  function mysite_type_storylink_title($ty
88  }  }
89    
90  /**  /**
91   * Implements mysite_type_hook_data().   * Implements mysite_type_hook_data().
92   */   */
93  function mysite_type_storylink_data($type_id = NULL) {  function mysite_type_storylink_data($type_id = NULL) {
94    if(!empty($type_id)) {    if (!empty($type_id)) {
95      $sql = db_rewrite_sql("SELECT n.nid, n.changed FROM {node} n WHERE n.type = 'storylink' AND n.status = 1 AND n.uid = %d ORDER BY n.changed DESC");      $sql = db_rewrite_sql("SELECT n.nid, n.changed FROM {node} n WHERE n.type = 'storylink' AND n.status = 1 AND n.uid = %d ORDER BY n.changed DESC");
96      $result = db_query_range($sql, $type_id, 0, variable_get('mysite_elements', 5));      $result = db_query_range($sql, $type_id, 0, variable_get('mysite_elements', 5));
97      $data = array(      $data = array(
# Line 97  function mysite_type_storylink_data($typ Line 100  function mysite_type_storylink_data($typ
100        );        );
101      $items = array();      $items = array();
102      $i = 0;      $i = 0;
103      $type = mysite_type_storylink(FALSE);      $type = mysite_type_storylink(FALSE);
104      while ($nid = db_fetch_object($result)) {      while ($nid = db_fetch_object($result)) {
105        $node = node_load(array('nid' => $nid->nid));        $node = node_load(array('nid' => $nid->nid));
106        $items[$i]['type'] = $node->type;        $items[$i]['type'] = $node->type;
107        $items[$i]['link'] = l($node->title, 'node/'. $nid->nid, array('target' => $type['link_target']));        $items[$i]['link'] = l($node->title, 'node/'. $nid->nid, array('target' => $type['link_target']));
108        $items[$i]['title'] = check_plain($node->title);        $items[$i]['title'] = check_plain($node->title);
109        $items[$i]['subtitle'] = NULL;        $items[$i]['subtitle'] = NULL;
110        $items[$i]['date'] = $node->changed;        $items[$i]['date'] = $node->changed;
111        $items[$i]['uid'] = $node->uid;        $items[$i]['uid'] = $node->uid;
112        $items[$i]['author'] = check_plain($node->name);        $items[$i]['author'] = check_plain($node->name);
113        $items[$i]['teaser'] = mysite_teaser($node);        $items[$i]['teaser'] = mysite_teaser($node);
114        $items[$i]['nid'] = $node->nid;        $items[$i]['nid'] = $node->nid;
115        $i++;        $i++;
116      }      }
# Line 115  function mysite_type_storylink_data($typ Line 118  function mysite_type_storylink_data($typ
118      return $data;      return $data;
119    }    }
120    drupal_set_message(t('Could not find data'), 'error');    drupal_set_message(t('Could not find data'), 'error');
121    return;    return;
122  }  }
123    
124  /**  /**
125   * Implements mysite_type_hook_block().   * Implements mysite_type_hook_block().
126   */   */
127  function mysite_type_storylink_block($arg, $op = 'view') {  function mysite_type_storylink_block($arg, $op = 'view') {
128    global $user;    global $user;
# Line 132  function mysite_type_storylink_block($ar Line 135  function mysite_type_storylink_block($ar
135        $data['type_id'] = $storylink->uid;        $data['type_id'] = $storylink->uid;
136        $content = mysite_block_handler($data);        $content = mysite_block_handler($data);
137        return $content;        return $content;
138      }      }
139    }    }
140  }  }
141    
142  /**  /**
143   * Implements mysite_type_hook_block_node().   * Implements mysite_type_hook_block_node().
144   */   */
145  function mysite_type_storylink_block_node($nid, $type) {  function mysite_type_storylink_block_node($nid, $type) {
146    if ($type == 'storylink') {    if ($type == 'storylink') {
# Line 154  function mysite_type_storylink_block_nod Line 157  function mysite_type_storylink_block_nod
157  }  }
158    
159  /**  /**
160   * Implements mysite_type_hook_search().   * Implements mysite_type_hook_search().
  *  
  * @ingroup forms  
161   */   */
162  function mysite_type_storylink_search($uid = NULL) {  function mysite_type_storylink_search($uid = NULL) {
163    if (!is_null($uid)) {    if (!is_null($uid)) {
164      $output .= drupal_get_form('mysite_type_storylink_search_form', $uid);      $output .= drupal_get_form('mysite_type_storylink_search_form', $uid);
165      return $output;      return $output;
166    }    }
167  }  }
168    
169  /**  /**
170   * FormsAPI for mysite_type_storylink_search()   * FormsAPI for mysite_type_storylink_search()
  *  
  * @ingroup forms  
171   */   */
172  function mysite_type_storylink_search_form($uid) {  function mysite_type_storylink_search_form($uid) {
173    $form['add_storylink']['storylink_title'] = array('#type' => 'textfield',    $form['add_storylink']['storylink_title'] = array('#type' => 'textfield',
# Line 178  function mysite_type_storylink_search_fo Line 177  function mysite_type_storylink_search_fo
177      '#description' => t('The user name of the storylink you wish to add.'),      '#description' => t('The user name of the storylink you wish to add.'),
178      '#required' => FALSE, // this must be false, since all the search for are the same form      '#required' => FALSE, // this must be false, since all the search for are the same form
179      '#autocomplete_path' => 'autocomplete/mysite/storylink'      '#autocomplete_path' => 'autocomplete/mysite/storylink'
180    );    );
181    $form['add_storylink']['uid'] = array('#type' => 'hidden', '#value' => $uid);    $form['add_storylink']['uid'] = array('#type' => 'hidden', '#value' => $uid);
182    $form['add_storylink']['type'] = array('#type' => 'hidden', '#value' => 'storylink');    $form['add_storylink']['type'] = array('#type' => 'hidden', '#value' => 'storylink');
183    $form['add_storylink']['submit'] = array('#type' => 'submit', '#value' =>t('Add storylink'));    $form['add_storylink']['submit'] = array('#type' => 'submit', '#value' => t('Add storylink'));
184    return $form;    return $form;
185  }  }
186    
187  /**  /**
188   * Implements mysite_type_hook_search_form_submit().   * Implements mysite_type_hook_search_form_submit().
189   *   */
  * @ingroup forms  
  */  
190  function mysite_type_storylink_search_submit($form_id, $form_values) {  function mysite_type_storylink_search_submit($form_id, $form_values) {
191    // we use LIKE here in case JavaScript autocomplete support doesn't work.    // we use LIKE here in case JavaScript autocomplete support doesn't work.
192    // or in case the user doesn't autocomplete the form    // or in case the user doesn't autocomplete the form
# Line 200  function mysite_type_storylink_search_su Line 197  function mysite_type_storylink_search_su
197      $data[$count]['type'] = $form_values['type'];      $data[$count]['type'] = $form_values['type'];
198      $data[$count]['type_id'] = $storylink->uid;      $data[$count]['type_id'] = $storylink->uid;
199      $data[$count]['title'] = mysite_type_storylink_title($storylink->uid, $storylink->name);      $data[$count]['title'] = mysite_type_storylink_title($storylink->uid, $storylink->name);
200      $data[$count]['description'] = t('The storylink posts of %user', array('%user' => $storylink->name));      $data[$count]['description'] = t('The storylink posts of %user', array('%user' => $storylink->name));
201      $count++;      $count++;
202    }    }
203    // pass the $data to the universal handler    // pass the $data to the universal handler
# Line 209  function mysite_type_storylink_search_su Line 206  function mysite_type_storylink_search_su
206  }  }
207    
208  /**  /**
209   * Implements mysite_type_hook_autocomplete().   * Implements mysite_type_hook_autocomplete().
  *  
  * @ingroup forms  
210   */   */
211  function mysite_type_storylink_autocomplete($string) {  function mysite_type_storylink_autocomplete($string) {
212    $matches = array();    $matches = array();
# Line 221  function mysite_type_storylink_autocompl Line 216  function mysite_type_storylink_autocompl
216    }    }
217    return $matches;    return $matches;
218  }  }
219    
220  /**  /**
221   * Implements mysite_type_hook_clear().   * Implements mysite_type_hook_clear().
222   */   */
# Line 233  function mysite_type_storylink_clear($ty Line 228  function mysite_type_storylink_clear($ty
228    while ($item = db_fetch_array($result)) {    while ($item = db_fetch_array($result)) {
229      $sql = "SELECT DISTINCT(u.uid) FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' AND u.uid = %d";      $sql = "SELECT DISTINCT(u.uid) FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'storylink' AND u.uid = %d";
230      $check = db_fetch_object(db_query($sql, $item['type_id']));      $check = db_fetch_object(db_query($sql, $item['type_id']));
231      if(empty($check->uid)) {      if (empty($check->uid)) {
232        $data[$item['mid']]  = $item;        $data[$item['mid']]  = $item;
233      }      }
234    }    }
235    return $data;    return $data;
236  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.2