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

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

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

revision 1.3, Sat Jan 5 20:47:55 2008 UTC revision 1.4, Sun Apr 6 23:08:26 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: weblink.inc,v 1.2 2007/10/07 19:09:51 agentken Exp $  // $Id: weblink.inc,v 1.3 2008/01/05 20:47:55 agentken Exp $
3    
4  /**  /**
5   * @file   * @file
6   * Handles weblink nodes created by the Links module   * Handles weblink nodes created by the Links module
7   */   *
   
 /**  
8   * INSTALLATION   * INSTALLATION
9   *   *
10   * Requires: links.module AND links_weblink.module   * Requires: links.module AND links_weblink.module
# Line 14  Line 12 
12   * Settings: No   * Settings: No
13   *   *
14   * Author: suchold-it   * Author: suchold-it
15     *
16     * @ingroup mysite_plugins
17   */   */
18    
19  /**  /**
20   * Implements mysite_type_hook().   * Implements mysite_type_hook().
21   *   *
22   * Taxonomy module and Links Weblink module must be enabled for this plugin to register.   * Taxonomy module and Links Weblink module must be enabled for this plugin to register.
  *  
23   */   */
24  function mysite_type_weblink($get_options = TRUE) {  function mysite_type_weblink($get_options = TRUE) {
25    if(module_exists('taxonomy') && module_exists('links_weblink')) {    if (module_exists('taxonomy') && module_exists('links_weblink')) {
26      $type = array(      $type = array(
27        'name' => t('Web Links'),        'name' => t('Web Links'),
28        'description' => t('<b>Weblinks</b>: All weblinks from a specific category.'),        'description' => t('<b>Weblinks</b>: All weblinks from a specific category.'),
# Line 38  function mysite_type_weblink($get_option Line 37  function mysite_type_weblink($get_option
37        'search' => TRUE        'search' => TRUE
38      );      );
39      $basic_settings = variable_get('mysite_basic_weblink_settings', array());      $basic_settings = variable_get('mysite_basic_weblink_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_weblink_options();        $type['options'] = mysite_type_weblink_options();
43      }      }
# Line 53  function mysite_type_weblink_active($typ Line 52  function mysite_type_weblink_active($typ
52    // there must be active and allowed taxonomies    // there must be active and allowed taxonomies
53    $value = TRUE;    $value = TRUE;
54    $message = '';    $message = '';
55    $br = '';    $br = '';
56    $tree = taxonomy_get_vocabularies('weblink');    $tree = taxonomy_get_vocabularies('weblink');
57    if (empty($tree)) {    if (empty($tree)) {
58      $value = FALSE;      $value = FALSE;
# Line 86  function mysite_type_weblink_options() { Line 85  function mysite_type_weblink_options() {
85    if (is_array($terms) && !empty($terms)) {    if (is_array($terms) && !empty($terms)) {
86      $i =0;      $i =0;
87      foreach ($terms as $key => $value) {      foreach ($terms as $key => $value) {
88        foreach($value as $term) {        foreach ($value as $term) {
89          $depth = str_repeat('-', $term->depth) . ' ';          $depth = str_repeat('-', $term->depth) .' ';
90          $options['group'][] = $key;          $options['group'][] = $key;
91          $options['name'][] = $depth . $term->name;          $options['name'][] = $depth . $term->name;
92          $options['type_id'][] = $term->tid;          $options['type_id'][] = $term->tid;
93          $options['type'][] = 'weblink';          $options['type'][] = 'weblink';
94          $options['icon'][] = mysite_get_icon('weblink', $term->tid);          $options['icon'][] = mysite_get_icon('weblink', $term->tid);
95          $i++;          $i++;
96        }        }
97      }      }
# Line 101  function mysite_type_weblink_options() { Line 100  function mysite_type_weblink_options() {
100  }  }
101    
102  /**  /**
103   * Implements mysite_type_hook_title().   * Implements mysite_type_hook_title().
104   */   */
105  function mysite_type_weblink_title($type_id = NULL, $title = NULL) {  function mysite_type_weblink_title($type_id = NULL, $title = NULL) {
106    if(!empty($type_id)) {    if (!empty($type_id)) {
107      if(is_null($title)) {      if (is_null($title)) {
108        $term = taxonomy_get_term($type_id);        $term = taxonomy_get_term($type_id);
109        $title = $term->name;        $title = $term->name;
110      }      }
111      $type = mysite_type_weblink(FALSE);      $type = mysite_type_weblink(FALSE);
112      $title = $type['prefix'] . ' ' . $title . ' ' . $type['suffix'];      $title = $type['prefix'] .' '. $title .' '. $type['suffix'];
113      $title = trim(rtrim($title));      $title = trim(rtrim($title));
114      return $title;      return $title;
115    }    }
# Line 119  function mysite_type_weblink_title($type Line 118  function mysite_type_weblink_title($type
118  }  }
119    
120  /**  /**
121   * Implements mysite_type_hook_data().   * Implements mysite_type_hook_data().
122   */   */
123  function mysite_type_weblink_data($type_id = NULL) {  function mysite_type_weblink_data($type_id = NULL) {
124    if(!empty($type_id)) {    if (!empty($type_id)) {
125      $order =  variable_get('mysite_weblink_sort', array());      $order =  variable_get('mysite_weblink_sort', array());
126      if ($order == "click") {      if ($order == "click") {
127        $order_sql = "ln.clicks";        $order_sql = "ln.clicks";
128      }      }
129      else {      else {
130        $order_sql = "n.changed";        $order_sql = "n.changed";
131      }      }
# Line 164  function mysite_type_weblink_data($type_ Line 163  function mysite_type_weblink_data($type_
163  }  }
164    
165  /**  /**
166   * Implements mysite_type_hook_block().   * Implements mysite_type_hook_block().
167   */   */
168  function mysite_type_weblink_block($arg, $op = 'view') {  function mysite_type_weblink_block($arg, $op = 'view') {
169    global $user;    global $user;
# Line 180  function mysite_type_weblink_block($arg, Line 179  function mysite_type_weblink_block($arg,
179  }  }
180    
181  /**  /**
182   * Implements mysite_type_hook_search().   * Implements mysite_type_hook_search().
  *  
  * @ingroup forms  
183   */   */
184  function mysite_type_weblink_search($uid = NULL) {  function mysite_type_weblink_search($uid = NULL) {
185    if (!is_null($uid)) {    if (!is_null($uid)) {
# Line 193  function mysite_type_weblink_search($uid Line 190  function mysite_type_weblink_search($uid
190    
191  /**  /**
192   * FormsAPI for mysite_type_weblink_search()   * FormsAPI for mysite_type_weblink_search()
  *  
  * @ingroup forms  
193   */   */
194  function mysite_type_weblink_search_form($uid) {  function mysite_type_weblink_search_form($uid) {
195    $form['add_weblink']['weblink_title'] = array('#type' => 'textfield',    $form['add_weblink']['weblink_title'] = array('#type' => 'textfield',
# Line 206  function mysite_type_weblink_search_form Line 201  function mysite_type_weblink_search_form
201    );    );
202    $form['add_weblink']['uid'] = array('#type' => 'hidden', '#value' => $uid);    $form['add_weblink']['uid'] = array('#type' => 'hidden', '#value' => $uid);
203    $form['add_weblink']['type'] = array('#type' => 'hidden', '#value' => 'weblink');    $form['add_weblink']['type'] = array('#type' => 'hidden', '#value' => 'weblink');
204    $form['add_weblink']['submit'] = array('#type' => 'submit', '#value' =>t('Add category'));    $form['add_weblink']['submit'] = array('#type' => 'submit', '#value' => t('Add category'));
205    return $form;    return $form;
206  }  }
207    
208  /**  /**
209   * Implements mysite_type_hook_search_form_submit().   * Implements mysite_type_hook_search_form_submit().
210   *   */
  * @ingroup forms  
  */  
211  function mysite_type_weblink_search_form_submit($form_id, $form_values) {  function mysite_type_weblink_search_form_submit($form_id, $form_values) {
212    // exclude vocabularies not allowed by the site settings    // exclude vocabularies not allowed by the site settings
213    $in = _mysite_type_weblink_in();    $in = _mysite_type_weblink_in();
214      $placeholders = array_fill(0, count($in), "'%s'");
215    // we use LIKE here in case JavaScript autocomplete support doesn't work.    // we use LIKE here in case JavaScript autocomplete support doesn't work.
216    // or in case the user doesn't autocomplete the form    // or in case the user doesn't autocomplete the form
217    $sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.name LIKE LOWER('%s%%') AND t.vid IN ($in)", 't', 'tid');    $sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.name LIKE LOWER('%s%%') AND t.vid IN (". implode(',', $placeholders) .")", 't', 'tid', $in);
218    $result = db_query($sql, strtolower($form_values['weblink_title']));    $result = db_query($sql, strtolower($form_values['weblink_title']));
219    $count = 0;    $count = 0;
220    while ($term = db_fetch_object($result)) {    while ($term = db_fetch_object($result)) {
# Line 237  function mysite_type_weblink_search_form Line 231  function mysite_type_weblink_search_form
231  }  }
232    
233  /**  /**
234   * Implements mysite_type_hook_autocomplete().   * Implements mysite_type_hook_autocomplete().
  *  
  * @ingroup forms  
235   */   */
236  function mysite_type_weblink_autocomplete($string) {  function mysite_type_weblink_autocomplete($string) {
237    $matches = array();    $matches = array();
238    // exclude vocabularies not allowed by the site settings    // exclude vocabularies not allowed by the site settings
239    $in = _mysite_type_weblink_in();    $in = _mysite_type_weblink_in();
240    $sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.name LIKE LOWER('%s%%') AND t.vid IN ($in)", 't', 'tid');    $placeholders = array_fill(0, count($in), "'%s'");
241      $sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.name LIKE LOWER('%s%%') AND t.vid IN (". implode(',', $placeholders) .")", 't', 'tid', $in);
242    $result = db_query_range($sql, $string, 0, 10);    $result = db_query_range($sql, $string, 0, 10);
243    while ($term = db_fetch_object($result)) {    while ($term = db_fetch_object($result)) {
244      $matches[$term->name] = check_plain($term->name);      $matches[$term->name] = check_plain($term->name);
# Line 260  function mysite_type_weblink_autocomplet Line 253  function mysite_type_weblink_autocomplet
253   *   *
254   * @return $in   * @return $in
255   * An IN() modifier for SQL.   * An IN() modifier for SQL.
  *  
  * @ingroup includes  
256   */   */
257  function _mysite_type_weblink_in() {  function _mysite_type_weblink_in() {
258    $in = NULL;    $in = array();
259    $vocabularies = variable_get('mysite_weblink_vocabularies', array());    $vocabularies = variable_get('mysite_weblink_vocabularies', array());
260    if (is_array($vocabularies) && !empty($vocabularies)) {    if (is_array($vocabularies) && !empty($vocabularies)) {
261      foreach ($vocabularies as $vid) {      foreach ($vocabularies as $vid) {
262        if ($vid > 0) {        if ($vid > 0) {
263          $in .= $vid . ', ';          $in[] = $vid;
264        }        }
265      }      }
     $in = rtrim($in, ', ');  
266    }    }
267    return $in;    return $in;
268  }  }
269    
270  /**  /**
271   * Implements mysite_type_hook_clear().   * Implements mysite_type_hook_clear().
272   */   */
273  function mysite_type_weblink_clear($type) {  function mysite_type_weblink_clear($type) {
274    // fetch all the active records of this type and see if they really exist in the proper table    // fetch all the active records of this type and see if they really exist in the proper table
275    $sql = "SELECT mid, uid, type_id, title FROM {mysite_data} WHERE type = '%s'";    $sql = "SELECT mid, uid, type_id, title FROM {mysite_data} WHERE type = '%s'";
# Line 288  function mysite_type_weblink_clear($type Line 278  function mysite_type_weblink_clear($type
278    while ($item = db_fetch_array($result)) {    while ($item = db_fetch_array($result)) {
279      $sql = "SELECT tid FROM {term_data} WHERE tid = %d";      $sql = "SELECT tid FROM {term_data} WHERE tid = %d";
280      $check = db_fetch_object(db_query($sql, $item['type_id']));      $check = db_fetch_object(db_query($sql, $item['type_id']));
281      if(empty($check->tid)) {      if (empty($check->tid)) {
282        $data[$item['mid']]  = $item;        $data[$item['mid']]  = $item;
283      }      }
284    }    }
# Line 297  function mysite_type_weblink_clear($type Line 287  function mysite_type_weblink_clear($type
287    
288  /**  /**
289   * Implements mysite_type_hook_settings().   * Implements mysite_type_hook_settings().
290   */   */
291  function mysite_type_weblink_settings() {  function mysite_type_weblink_settings() {
292    $vocabularies = taxonomy_get_vocabularies('weblink');    $vocabularies = taxonomy_get_vocabularies('weblink');
293    unset($vocabularies[$forum]);    unset($vocabularies[$forum]);
# Line 311  function mysite_type_weblink_settings() Line 301  function mysite_type_weblink_settings()
301    
302  /**  /**
303   * FormsAPI for mysite_type_weblink_settings   * FormsAPI for mysite_type_weblink_settings
  *  
  * @ingroup forms  
304   */   */
305  function mysite_type_weblink_settings_form($vocabularies) {  function mysite_type_weblink_settings_form($vocabularies) {
306    foreach($vocabularies as $vocabulary) {    foreach ($vocabularies as $vocabulary) {
307      $options[$vocabulary->vid] = $vocabulary->name;      $options[$vocabulary->vid] = $vocabulary->name;
308    }    }
309    $form['mysite_weblink']['mysite_weblink_vocabularies'] = array(    $form['mysite_weblink']['mysite_weblink_vocabularies'] = array(
310        '#type' => 'checkboxes', '#title' => t('Allowed Vocabularies'), '#default_value' => variable_get('mysite_weblink_vocabularies', array()),        '#type' => 'checkboxes', '#title' => t('Allowed vocabularies'), '#default_value' => variable_get('mysite_weblink_vocabularies', array()),
311        '#options' =>  $options,        '#options' =>  $options,
312        '#required' => FALSE,        '#required' => FALSE,
313        '#description' => t('What weblinks vocabularies should be displayed to MySite users?')        '#description' => t('What weblinks vocabularies should be displayed to MySite users?')
314    );    );
315    $options2 = array("change"=>t('Last change'),"click"=>t('Number of clicks'));    $options2 = array('change' => t('Last change'), 'click' => t('Number of clicks'));
316    $form['mysite_weblink']['mysite_weblink_sort'] = array(    $form['mysite_weblink']['mysite_weblink_sort'] = array(
317        '#type' => 'radios', '#title' => t('Sorting'), '#default_value' => variable_get('mysite_weblink_sort', array()),        '#type' => 'radios', '#title' => t('Sorting'), '#default_value' => variable_get('mysite_weblink_sort', array()),
318        '#options' =>  $options2,        '#options' =>  $options2,

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2