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

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

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

revision 1.6, Sat Jan 5 20:47:55 2008 UTC revision 1.7, Sun Apr 6 23:08:26 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: refine.inc,v 1.5 2007/10/28 16:04:56 agentken Exp $  // $Id: refine.inc,v 1.6 2008/01/05 20:47:55 agentken Exp $
 // Addresses http://drupal.org/node/93060  
3    
4  /**  /**
5     * @file
6     * Addresses http://drupal.org/node/93060
7     *
8   * INSTALLATION   * INSTALLATION
9   *   *
10   * Requires: refine_by_taxo.module   * Requires: refine_by_taxo.module
# Line 10  Line 12 
12   * Settings: No   * Settings: No
13   *   *
14   * Author: agentrickard   * Author: agentrickard
15     *
16     * @ingroup mysite_plugins
17   */   */
18    
19  /**  /**
20   * Implements mysite_type_hook().   * Implements mysite_type_hook().
21   *   *
22   * Taxonomy module and Refine_by_taxo module must be enabled for this plugin to register.   * Taxonomy module and Refine_by_taxo module must be enabled for this plugin to register.
  *  
23   */   */
24  function mysite_type_refine($get_options = TRUE) {  function mysite_type_refine($get_options = TRUE) {
25    if(module_exists('refine_by_taxo') && module_exists('taxonomy')) {    if (module_exists('refine_by_taxo') && module_exists('taxonomy')) {
26      $type = array(      $type = array(
27        'name' => t('Refined Categories'),        'name' => t('Refined Categories'),
28        'description' => t('<b>Refined Categories</b>: Posts that match multiple terms.'),        'description' => t('<b>Refined Categories</b>: Posts that match multiple terms.'),
29        'include' => 'refine',        'include' => 'refine',
30        'prefix' => t(''),        'prefix' => t(''),
31        'suffix' => t('articles'),        'suffix' => t('articles'),
32        'category' => t('Content'),        'category' => t('Content'),
# Line 34  function mysite_type_refine($get_options Line 37  function mysite_type_refine($get_options
37        'search' => FALSE        'search' => FALSE
38      );      );
39      $basic_settings = variable_get('mysite_basic_refine_settings', array());      $basic_settings = variable_get('mysite_basic_refine_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_refine_options();        $type['options'] = mysite_type_refine_options();
43      }      }
# Line 71  function mysite_type_refine_options() { Line 74  function mysite_type_refine_options() {
74        $options['name'][] = mysite_type_refine_title($refine->myid, $refine->title);        $options['name'][] = mysite_type_refine_title($refine->myid, $refine->title);
75        $options['type_id'][] = $refine->myid;        $options['type_id'][] = $refine->myid;
76        $options['type'][] = 'refine';        $options['type'][] = 'refine';
77        $options['icon'][] = mysite_get_icon('refine', $refine->myid);        $options['icon'][] = mysite_get_icon('refine', $refine->myid);
78      }      }
79    }    }
80    return $options;    return $options;
81  }  }
82    
83  /**  /**
84   * Implements mysite_type_hook_title().   * Implements mysite_type_hook_title().
85   */   */
86  function mysite_type_refine_title($type_id = NULL, $title = NULL) {  function mysite_type_refine_title($type_id = NULL, $title = NULL) {
87    if(!empty($type_id)) {    if (!empty($type_id)) {
88      if(is_null($title)) {      if (is_null($title)) {
89        $data = mysite_get_custom('refine', $type_id, FALSE);        $data = mysite_get_custom('refine', $type_id, FALSE);
90        $title = $data->title;        $title = $data->title;
91      }      }
92      $type = mysite_type_refine(FALSE);      $type = mysite_type_refine(FALSE);
93      $title = $type['prefix'] .' '. $title .' '. $type['suffix'];      $title = $type['prefix'] .' '. $title .' '. $type['suffix'];
94      $title = trim(rtrim($title));      $title = trim(rtrim($title));
# Line 96  function mysite_type_refine_title($type_ Line 99  function mysite_type_refine_title($type_
99  }  }
100    
101  /**  /**
102   * Implements mysite_type_hook_data().   * Implements mysite_type_hook_data().
103   */   */
104  function mysite_type_refine_data($type_id = NULL) {  function mysite_type_refine_data($type_id = NULL) {
105    if(!empty($type_id)) {    if (!empty($type_id)) {
106      $tids = '';      $tids = '';
107      $data = mysite_get_custom('refine', $type_id);      $data = mysite_get_custom('refine', $type_id);
108      $terms = explode(',', $data->type_key);      $terms = explode(',', $data->type_key);
# Line 107  function mysite_type_refine_data($type_i Line 110  function mysite_type_refine_data($type_i
110      $nids = array();      $nids = array();
111      while ($row = db_fetch_object($result)) {      while ($row = db_fetch_object($result)) {
112        $nids[] = $row->nid;        $nids[] = $row->nid;
113      }      }
114      // slice the array to limit results      // slice the array to limit results
115      $nodes = array_slice($nids, 0, variable_get('mysite_elements', 5));      $nodes = array_slice($nids, 0, variable_get('mysite_elements', 5));
116      $data = array(      $data = array(
117        'base' => 'taxonomy/term/'. $data->type_key,        'base' => 'taxonomy/term/'. $data->type_key,
118        'xml' => 'taxonomy/term/'. $data->type_key .'/0/feed'        'xml' => 'taxonomy/term/'. $data->type_key .'/0/feed'
# Line 124  function mysite_type_refine_data($type_i Line 127  function mysite_type_refine_data($type_i
127        $items[$i]['type'] = $node->type;        $items[$i]['type'] = $node->type;
128        $items[$i]['link'] = l($node->title, 'node/'. $node->nid, array('target' => $type['link_target']));        $items[$i]['link'] = l($node->title, 'node/'. $node->nid, array('target' => $type['link_target']));
129        $items[$i]['title'] = check_plain($node->title);        $items[$i]['title'] = check_plain($node->title);
130        $items[$i]['subtitle'] = NULL;        $items[$i]['subtitle'] = NULL;
131        $items[$i]['date'] = $node->changed;        $items[$i]['date'] = $node->changed;
132        $items[$i]['uid'] = $node->uid;        $items[$i]['uid'] = $node->uid;
133        $items[$i]['author'] = check_plain($node->name);        $items[$i]['author'] = check_plain($node->name);
134        $items[$i]['teaser'] = mysite_teaser($node);        $items[$i]['teaser'] = mysite_teaser($node);
135        $items[$i]['nid'] = $node->nid;        $items[$i]['nid'] = $node->nid;
136        $i++;        $i++;
137      }      }
138      $data['items'] = $items;      $data['items'] = $items;
139      return $data;      return $data;
140    }    }
141    drupal_set_message(t('Could not find data'), 'error');    drupal_set_message(t('Could not find data'), 'error');
142    return;    return;
143  }  }
144    
145  /**  /**
146   * Implements mysite_type_hook_block().   * Implements mysite_type_hook_block().
147   */   */
148  function mysite_type_refine_block($arg, $op = 'view') {  function mysite_type_refine_block($arg, $op = 'view') {
149    global $user;    global $user;
# Line 151  function mysite_type_refine_block($arg, Line 154  function mysite_type_refine_block($arg,
154      foreach ($terms as $term) {      foreach ($terms as $term) {
155        $taxo[$term] = taxonomy_get_term($term);        $taxo[$term] = taxonomy_get_term($term);
156        $name .= $taxo[$term]->name .', ';        $name .= $taxo[$term]->name .', ';
157      }      }
158      $name = rtrim($name, ', ');      $name = rtrim($name, ', ');
159      $myid = mysite_get_myid('refine', $arg[2], $name);      $myid = mysite_get_myid('refine', $arg[2], $name);
160      $data = array();      $data = array();
# Line 175  function mysite_type_refine_clear($type) Line 178  function mysite_type_refine_clear($type)
178    while ($item = db_fetch_array($result)) {    while ($item = db_fetch_array($result)) {
179      $sql = "SELECT tid FROM {term_data} WHERE tid IN (%s)";      $sql = "SELECT tid FROM {term_data} WHERE tid IN (%s)";
180      $check = db_fetch_object(db_query($sql, $item['type_key']));      $check = db_fetch_object(db_query($sql, $item['type_key']));
181      if(empty($check->tid)) {      if (empty($check->tid)) {
182        $data[$item['mid']]  = $item;        $data[$item['mid']]  = $item;
183      }      }
184    }    }
185    return $data;    return $data;
186  }  }
187    
188  /**  /**
189   * Implements mysite_type_hook_settings().   * Implements mysite_type_hook_settings().
190   */   */
191  function mysite_type_refine_settings() {  function mysite_type_refine_settings() {
192    mysite_check_settings('refine');    mysite_check_settings('refine');
193    $data = db_fetch_object(db_query("SELECT myid, title FROM {mysite_content} WHERE type = 'refine' AND myid = %d", intval(arg(5))));    $data = db_fetch_object(db_query("SELECT myid, title FROM {mysite_content} WHERE type = 'refine' AND myid = %d", intval(arg(5))));
# Line 198  function mysite_type_refine_settings() { Line 201  function mysite_type_refine_settings() {
201      $output .= t('<h3>Rename Groups</h3>');      $output .= t('<h3>Rename Groups</h3>');
202      $output .= t('<p>The following content groups have been created by the Refine-By-Taxo module.</p>');      $output .= t('<p>The following content groups have been created by the Refine-By-Taxo module.</p>');
203      $header = array(      $header = array(
204        array('data' => t('ID #'), 'field' =>'myid'),        array('data' => t('ID #'), 'field' => 'myid'),
205        array('data' => t('Title'), 'field' => 'title'),        array('data' => t('Title'), 'field' => 'title'),
206        array('data' => t('Terms'), 'field' => 'type_key'),        array('data' => t('Terms'), 'field' => 'type_key'),
207        array('data' => t('Rename'))        array('data' => t('Rename'))
208      );      );
209      $limit = 25;      $limit = 25;
210      $sql = "SELECT myid, type_key, title FROM {mysite_content} WHERE type = 'refine'" . tablesort_sql($header);      $sql = "SELECT myid, type_key, title FROM {mysite_content} WHERE type = 'refine'" . tablesort_sql($header);
211      $result = pager_query($sql, $limit);      $result = pager_query($sql, $limit);
212      $rows = array();      $rows = array();
213      while ($group = db_fetch_object($result)) {      while ($group = db_fetch_object($result)) {
214        $rows[] = array($group->myid, l($group->title, 'taxonomy/term/'. $group->type_key), $group->type_key, l(t('Edit name'), 'admin/settings/mysite/type/refine/'. $group->myid));        $rows[] = array($group->myid, l($group->title, 'taxonomy/term/'. $group->type_key), $group->type_key, l(t('Edit name'), 'admin/settings/mysite/type/refine/'. $group->myid));
215      }      }
216      if (!empty($rows)) {      if (!empty($rows)) {
217        $output .= theme_table($header, $rows);        $output .= theme_table($header, $rows);
218        $output .= theme('pager', NULL, $limit, 0);        $output .= theme('pager', NULL, $limit, 0);
219      }      }
220      return $output;      return $output;
221    }    }
222  }  }
223    
224  /**  /**
225   * FormsAPI for adding new content groups   * FormsAPI for adding new content groups
  * @ingroup forms  
226   */   */
227  function mysite_type_refine_add_form() {  function mysite_type_refine_add_form() {
228    // get the vocabularies    // get the vocabularies
229    $vocabularies = taxonomy_get_vocabularies();    $vocabularies = taxonomy_get_vocabularies();
230    $form['refine'] = array(    $form['refine'] = array(
# Line 231  function mysite_type_refine_add_form() { Line 233  function mysite_type_refine_add_form() {
233      '#collapsible' => TRUE,      '#collapsible' => TRUE,
234      '#collapsed' => FALSE,      '#collapsed' => FALSE,
235      '#description' => t('<p>Select as many terms as you like to create a new content view.  These items will show all content that matches term1 AND term2 AND so forth.</p>')      '#description' => t('<p>Select as many terms as you like to create a new content view.  These items will show all content that matches term1 AND term2 AND so forth.</p>')
236    );    );
237    $form['refine']['title'] = array(    $form['refine']['title'] = array(
238      '#type' => 'textfield',      '#type' => 'textfield',
239      '#size' => 30,      '#size' => 30,
# Line 246  function mysite_type_refine_add_form() { Line 248  function mysite_type_refine_add_form() {
248            $options[$vid][$term->tid] = $term->name;            $options[$vid][$term->tid] = $term->name;
249          }          }
250          $form['refine'][$vid]['terms'] = array(          $form['refine'][$vid]['terms'] = array(
251            '#type' => 'select',            '#type' => 'select',
252            '#title' => check_plain($vocabulary->name),            '#title' => check_plain($vocabulary->name),
253            '#default_value' => NULL,            '#default_value' => NULL,
254            '#options' =>  $options[$vid],            '#options' =>  $options[$vid],
255            '#multiple' => TRUE,            '#multiple' => TRUE,
256            '#description' => t('Select the vocabulary terms to combine.')            '#description' => t('Select the vocabulary terms to combine.')
257          );          );
258        }        }
259      }      }
260    }    }
# Line 268  function mysite_type_refine_add_form() { Line 270  function mysite_type_refine_add_form() {
270   *   *
271   * @param $data   * @param $data
272   * The id and title of the element from {mysite_content}   * The id and title of the element from {mysite_content}
  * @ingroup forms  
273   */   */
274  function mysite_type_refine_title_form($data) {  function mysite_type_refine_title_form($data) {
275    $form = array();    $form = array();
# Line 290  function mysite_type_refine_title_form($ Line 291  function mysite_type_refine_title_form($
291    
292  /**  /**
293   * FormsAPI for mysite_type_refine_title_form()   * FormsAPI for mysite_type_refine_title_form()
  * @ingroup forms  
294   */   */
295  function mysite_type_refine_title_form_validate($form_id, $form_values) {  function mysite_type_refine_title_form_validate($form_id, $form_values) {
296    $sql = "SELECT myid FROM {mysite_content} WHERE lower(title) = '%s' AND type = 'refine' AND myid != %d";    $sql = "SELECT myid FROM {mysite_content} WHERE lower(title) = '%s' AND type = 'refine' AND myid <> %d";
297    $check = db_result(db_query($sql, trim(strtolower($form_values['title'])), $form_values['myid']));    $check = db_result(db_query($sql, trim(strtolower($form_values['title'])), $form_values['myid']));
298    if ($check) {    if ($check) {
299      form_set_error($form_values['myid'], t('The title must be unique.'));      form_set_error($form_values['myid'], t('The title must be unique.'));
300    }    }
301  }  }
302    
303  /**  /**
304   * FormsAPI for mysite_type_refine_title_form()   * FormsAPI for mysite_type_refine_title_form()
  * @ingroup forms  
305   */   */
306  function mysite_type_refine_title_form_submit($form_id, $form_values) {  function mysite_type_refine_title_form_submit($form_id, $form_values) {
307    $sql = "UPDATE {mysite_content} SET title = '%s' WHERE myid = %d AND type = 'refine'";    $sql = "UPDATE {mysite_content} SET title = '%s' WHERE myid = %d AND type = 'refine'";
# Line 313  function mysite_type_refine_title_form_s Line 312  function mysite_type_refine_title_form_s
312    
313  /**  /**
314   * FormsAPI for mysite_type_refine_add_form()   * FormsAPI for mysite_type_refine_add_form()
  * @ingroup forms  
315   */   */
316  function mysite_type_refine_add_form_validate($form_id, $form_values) {  function mysite_type_refine_add_form_validate($form_id, $form_values) {
317    $sql = "SELECT myid FROM {mysite_content} WHERE lower(title) = '%s' AND type = 'refine'";    $sql = "SELECT myid FROM {mysite_content} WHERE lower(title) = '%s' AND type = 'refine'";
318    $check = db_fetch_object(db_query($sql, trim(strtolower($form_values['title']))));    $check = db_fetch_object(db_query($sql, trim(strtolower($form_values['title']))));
319    if ($check->myid > 0) {    if ($check->myid > 0) {
320      form_set_error($form_values['title'], t('The title must be unique.'));      form_set_error($form_values['title'], t('The title must be unique.'));
321    }    }
322    else {    else {
323      if (count($form_values['terms']) < 2) {      if (count($form_values['terms']) < 2) {
324        form_set_error($form_values['terms'], t('You must select at least two terms.'));        form_set_error($form_values['terms'], t('You must select at least two terms.'));
325      }      }
326      else {      else {
327        ksort($form_values['terms']);        ksort($form_values['terms']);
328        $terms = implode(',', $form_values['terms']);        $terms = implode(',', $form_values['terms']);
329        $sql = "SELECT myid FROM {mysite_content} WHERE type_key = '%s' AND type = '%s'";        $sql = "SELECT myid FROM {mysite_content} WHERE type_key = '%s' AND type = '%s'";
330        $data = db_fetch_object(db_query($sql, $terms, 'refine'));        $data = db_fetch_object(db_query($sql, $terms, 'refine'));
331        if ($data->myid > 0) {        if ($data->myid > 0) {
332          form_set_error($form_values['terms'], t('This content group already exists.'));          form_set_error($form_values['terms'], t('This content group already exists.'));
333        }        }
334      }      }
335    }    }
336  }  }
337    
338  /**  /**
339   * FormsAPI for mysite_type_refine_add_form()   * FormsAPI for mysite_type_refine_add_form()
  * @ingroup forms  
340   */   */
341  function mysite_type_refine_add_form_submit($form_id, $form_values) {  function mysite_type_refine_add_form_submit($form_id, $form_values) {
342    ksort($form_values['terms']);    ksort($form_values['terms']);
# Line 351  function mysite_type_refine_add_form_sub Line 348  function mysite_type_refine_add_form_sub
348    else {    else {
349      drupal_set_message(t('Insert failed'), 'error');      drupal_set_message(t('Insert failed'), 'error');
350    }    }
351  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.2